运行环境:ubuntu16.04 + opencv 2.4.13 + c++ (系统g++版本5.4.0)
#include <iostream>
#include <fstream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/ml/ml.hpp>
#define PostiveImageList "a.txt" //正样本图片文件列表【记住这个地方的文件名需要根据自己的实际情况进行修改】
using namespace std;
using namespace cv;
int CropImageCount = 0; //用于重命名resize后的图片
int main()
{
Mat src, dstImg;
string ImgName;
char saveName[256]; //resize之后图片的名字,256表示linux下面最大文件名的长度
ifstream fin(PostiveImageList); //打开原始正样本图片文件列表【记住这个地方的文件名需要根据自己的实际情况进行修改】
//一行一行读取文件列表
while( getline(fin,ImgName) )
{
cout<<"处理:"<<ImgName<<endl;
ImgName = "正样本图片/" + ImgName; //读取当前路径下,目录名为【正样本图片】下面的图片
src = imread(ImgName,1); //读取图片
resize(src, dstImg, Size(64, 128)); //对图片进行修改
sprintf(saveName,"统一大小的正样本图片/%03d.png",++CropImageCount); //生成resize之后的图片文件名
imwrite(saveName, dstImg); //保存文件
}
}
上面的代码是经过实测可行,最好是读懂的前提下,根据自己的实验环境进行稍加修改!
如有帮助点个赞呗!