C++ (opencv)读取文件夹下所有的图片(某一种类型,如JPG)(一次性读取)

`/testpath下面有两个文件夹,一个RGBFace,一个DepthFace,所有的图片都是彩色和PNG的
//读取文件夹下的图片文件名称
vector files;
//string filepath_RGB = testpath + “/RGBFace/*.jpg”;
string filepath_RGB = “E:/*.jpg”;
string filepath_Depth = testpath + “/RGBFace/*.jpg”;
cout << filepath_Depth << endl;
//E:\学习\深度学习\活体检测\数据集\Captrue_Data\dataset\test\real\RGBFace
vector images;
glob(filepath_Depth, files, false);
size_t count = files.size();
cout << count << endl;
for (int i = 0; i < count; i++) {
images.push_back(imread(files[i]));
cout << files[i] << endl;
//imshow(“jaj”, images[i]);
//waitKey(10);
}‘

这种方法时一次性将文件夹下的所有图片读取,vector保存images,然后可以对images处理。
不支持循环遍历,但是非常简便。
首先获取文件名
glob(filepath_Depth, files, false);
然后读取图片,添加到vector中
images.push_back(imread(files[i]));

猜你喜欢

转载自blog.csdn.net/fengzhongluoleidehua/article/details/80408877