opencv读取文件夹下的所有图片并写入新的文件中

在网上找了大多都是如下方法:

string input_path = "D:\\test_images\\in\\*.png";
vector image_list;   //opencv3.x中的string要改成String
cv::glob(input_path, image_list);  // 所有文件以具体路径方式,保存在list内
Mat image, out_image;
for (int i = 0; i < image_list.size(); i++) {
	string current_image_path = image_list[i];  // 获取第i个文件具体路径
	int pos1 = current_image_path.rfind("\\");
	int pos2 = current_image_path.rfind(".png");
	string image_name = current_image_path.substr(pos1 + 1 , pos2 - pos1 - 1);
	image = cv::imread(current_image_path, CV_LOAD_IMAGE_GRAYSCALE);
	string output_path = "D:\\test_images\\out\\" + image_name + ".bmp";
	cv::imwrite(output_path, out_image);
	cout<< output_path + " is ok" <

 

你可能感兴趣的:(opencv读取文件夹下的所有图片并写入新的文件中)