// SizeNomalization.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <io.h>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
void dir(string path)
{
long hFile = 0;
struct _finddata_t fileInfo;
string pathName, exdName;
Mat src;
Mat dst;
String fullPath;
String savePath;
String sPath = "原图像集\";
String sPathout = "输出图像集\";
int i = 0;
// \* 代表要遍历所有的类型
if ((hFile = _findfirst(pathName.assign(path).append("\*").c_str(), &fileInfo)) == -1)
{
return;
}
do
{
//判断文件的属性是文件夹还是文件
cout << fileInfo.name << (fileInfo.attrib&_A_SUBDIR ? "[folder]" : "[file]") << endl;
fullPath = path + '\' + (string)fileInfo.name;//读取图片的路径
savePath = sPathout + (string)fileInfo.name; //更改保存路径
if (fileInfo.attrib&_A_SUBDIR)
{
}
else
{
src = imread(fullPath);
//imshow("src",src);
resize(src, dst, Size(64, 64), (0, 0), (0, 0), cv::INTER_LINEAR); //更改保存尺寸大小
imwrite(savePath, dst);
}
} while (_findnext(hFile, &fileInfo) == 0);
_findclose(hFile);
return;
}
int main()
{
//要遍历的目录
string path = "原图像集";
dir(path);
system("pause");
return 0;
}// SizeNomalization.cpp : 定义控制台应用程序的入口点。
//