对有序的文件读取、变换、写入新的文件夹中,
如图所示,分别为读入和写出
对于无序的文件名,可以全选-----对第一幅图像重命名为1,则全部就都改为如图的文件名
附上程序
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
//define Width and Height
const int width = 60;
const int height = 80;
int main()
{
Mat src;
const int number = 20;//设定读取的图片数目
string src_image_name = "C:\\Users\\Administrator\\Desktop\\pic_save\\angle_x\\"; //读入的文件夹名
string src_image_name_after = "C:\\Users\\Administrator\\Desktop\\pic_save\\angle_x_after\\"; //写入的文件夹名
string src_image_name1 = src_image_name;
char num[number],num1[4] = "1 (",num2[6] = ")";
string num3 = ".jpg";
for ( int i = 1; i <= number; i++)
{
itoa(i,num,10);
src_image_name += num1;
src_image_name += num;
src_image_name += num2;
cout<<src_image_name<<endl;
//读入每一张图片,前提是每张图片按照1(1),1(2)...1(20)的顺序
src = imread(src_image_name,CV_LOAD_IMAGE_COLOR);
imshow(src_image_name,src);
//可对读入的图片进行改变
Mat dst;
//新写入的图片在文件夹中以1(1).....1(20)的顺序写入
imwrite(src_image_name_after+num1+num+num2+num3,dst);
src_image_name = src_image_name1;
}
waitKey(0);
system("pause");
return 0;
}