c++从文件夹读取图片并重命名保存至另一文件夹

#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace cv;
using namespace std;
int main()
{
	std::string pattern_jpg = "D:\\img\\*.jpg";

	std::vector<cv::String> image_files;
	cv::glob(pattern_jpg, image_files);
	if (image_files.size() == 0)
		{
			std::cout << "No image files[jpg]" << std::endl;
			return 0;
		}
	int k = 1;
	for (unsigned int frame = 0; frame < image_files.size(); ++frame)
		{//image_file.size()代表文件中总共的图片个数

			std::string Img_Name = "D:\\proc_img\\" + to_string(k) + ".jpg";
			Mat image = cv::imread(image_files[frame]);
			//cout << image_files.size() << endl;
			cv::imwrite(Img_Name, image);
			++k;
			//imshow("1", image);
			waitKey(300);
		}
	return 0;
}

 

posted @ 2019-12-16 14:42  Parallax  阅读(682)  评论(0编辑  收藏  举报