批量修改文件夹中的图片的名字,找了一些程序都不太好用,就自己总结写了一个。
#include<opencv2\opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
vector<Mat> RenamePic(cv::String Path);
int main()
{
cv::String Path = "D://workspace//opencv//Testcode//Testcode//*.jpg";
vector<Mat> images = RenamePic(Path);
return 0;
}
vector<Mat> RenamePic(cv::String Path)
{
vector<cv::String> filenames;
glob(Path, filenames, false);
vector<Mat> images;
size_t count = filenames.size();
for (size_t i = 0; i < count; i++)
{
stringstream str;
str << i << ".jpg";
string img_path = "D://workspace//opencv//Testcode//Testcode//testimg//";
imwrite(img_path+str.str(), imread(filenames[i]));
}
return images;
}