C++批量读取图片

#include 
#include 
#include 
#include 
#include 

using namespace std;
using namespace cv;

int main()
{
	//绝对路径下  类型为.bmp的照片
	string pattern_bmp = "C:\\Users\\Administrator\\Desktop\\PalamNet\\PalamNet\\PalamNet\\Tongji_Contactless_Palmprint_Dataset\\*.bmp";

	//创建一个String类型 名字为image_files的vector
	vector image_files;  

	//把pattern_bmp路径下所有文件名存在image_files中
	glob(pattern_bmp, image_files);
	/*cout << image_files[0] << endl;
	cout << image_files.size() << endl;*/
	
	//把文件名存到txt文件#include 
	ofstream out("imagesName.txt", ios::out);
	for (int i = 0; i < image_files.size(); ++i)
	{
		out << image_files[i] << endl;
	}

	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 = imread(image_files[frame]);
		imshow("1", image);
		waitKey(10);


	}
}

你可能感兴趣的:(C++)