#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <string>
#include <fstream>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
//创建文件名列表文件,若存在则清空文件
fstream file_list("name.txt", std::ios::out);
file_list.close();
//写入文件名列表到file_list.txt
system("dir /a /b >> name.txt");
file_list.open("name.txt", std::ios::in);
string filename;
string extension;
while(!file_list.eof()){
getline(file_list, filename);
int location = filename.find(".", 0);
if(location != string::npos){
extension = filename.substr(location);
if(0 == extension.compare(".jpg")
|| 0 == extension.compare(".png") ){
// do something with file
Mat src, dst;
src = imread(filename);
resize(src, dst, Size(32,32));
Mat faceROI = dst(Rect(4,4,24,24));
char image_name[128];
sprintf(image_name, "resize_crop_%s", filename.c_str());
imwrite(image_name, faceROI);
}
}
}
return 0;
}