#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace cv;
using namespace std;
int main() {
string pattern_jpg = "H:\\MyProjects\\Cpp_Projects\\LearningOpenCV3\\Bad\\*.jpg";
vector<String> image_files;
glob(pattern_jpg, image_files);
if (image_files.size() == 0) {
cout << "No image files[jpg]" << endl;
return 0;
}
for (unsigned int frame = 0; frame < image_files.size(); ++frame) {//image_file.size()代表文件中总共的图片个数
Mat image = cv::imread(image_files[frame]);
string s = to_string(frame);
string name = string(3 - s.size(), '0') + s + ".jpg";
imwrite(name, image);
cout << "已处理" << frame + 1 << "张照片" << endl;
waitKey(30);
}
}
转自opencv从文件夹中批量读取图片,并显示出来,有改动。