#include <opencv2\opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
//用void glob(String pattern, std::vector<String>& result, bool recursive = false);当recursive为false时,仅仅遍历指定文件夹内符合模式的文件,当recursive为true时,会同时遍历指定文件夹的子文件夹
//pattern要绝对路径 其它测试有问题
string pattern = "C:\\Users\\wangzhenlin\\Pictures\\Camera Roll\\*.PNG";
//cout << pattern << endl;
vector<Mat> images;
// 必须cv的String
vector<String> fn;
glob(pattern, fn, true);
size_t count = fn.size();
cout << count << endl;
for (int i = 0; i < count; i++) {
images.push_back(imread(fn[i]));
imshow("jaj", images[i]);
waitKey(100);
}
return 1;
}
二
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
//用void glob(String pattern, std::vector<String>& result, bool recursive = false);当recursive为false时,仅仅遍历指定文件夹内符合模式的文件,当recursive为true时,会同时遍历指定文件夹的子文件夹
//pattern要绝对路径 其它测试有问题
string pattern = "C:\\Users\\wangzhenlin\\Desktop\\新建文件夹 (3)\\样本\\*.jpg";
//cout << pattern << endl;
vector<Mat> images;
// 必须cv的String
vector<String> fn;
glob(pattern, fn, true);
size_t count = fn.size();
cout << count << endl;//162
for (int i = 0; i < count; i++) {
images.push_back(imread(fn[i]));
//imshow("jaj", images[i]);
string s = "C:\\Users\\wangzhenlin\\Desktop\\新建文件夹 (3)\\样本\\" + to_string(i) + ".jpg";
//string s = to_string(i);
imwrite(s, images[i]);
waitKey(100);
}
getchar();
return 1;
}