opencv 更改某path下图片大小


#include //project->settings->general->Use MFC in a shared DLL
#include "windows.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "cvaux.h"
#include "string"
#include "vector"
#include "iostream"

using namespace  std;
void FindAllFile(string _path, vector& filenames)
{
	CString path = _path.c_str();
	CFileFind finder;
	BOOL working = finder.FindFile(path + "\\*.*");
	while (working)
	{
		working = finder.FindNextFile();
		if (finder.IsDots())
			continue;
		if (finder.IsDirectory())
		{
			//递归遍历所有文件夹
			//CString::GetBuffer(0)=>string
			FindAllFile(finder.GetFilePath().GetBuffer(0), filenames);
		} 
		else 
		{
			string filename = finder.GetFileName();
			filenames.push_back(filename);
		}
	}
}

int main()
{
	vector filenames;
	string filePath = "C:\\Users\\careyjiang\\Desktop\\iphoneLargePicEnglish";
	FindAllFile(filePath, filenames);
	for (vector::iterator itr = filenames.begin(); itr != filenames.end();itr++)
	{
// 		size_t potPose = itr->find_last_of('.');		//扩展名
// 		if (itr->substr(potPose, string::npos) == ".jpg")///是jpg的图片
// 		{
// 			IplImage* curImage;
// 			string jpgPath = filePath+ "\\" + (*itr);
// 			curImage = cvLoadImage( jpgPath.c_str(),1);
// 			string bmpPath =filePath+ "\\"  + itr->substr(0,potPose) + ".bmp" ;
// 			cvSaveImage(bmpPath.c_str(),curImage);
// 			cvReleaseImage(&curImage);
// 		}		
		size_t potPose = itr->find_last_of('.');		//扩展名
		if (itr->substr(potPose, string::npos) == ".bmp")///是jpg的图片
		{
			IplImage* curImage;
			string jpgPath = filePath+ "\\" + (*itr);
			curImage = cvLoadImage( jpgPath.c_str(),CV_LOAD_IMAGE_COLOR);		
			float scale = 7.5/8;
			IplImage*  imageresize=cvCreateImage(cvSize(280,170),IPL_DEPTH_8U,3);  
			cvResize(curImage,imageresize,CV_INTER_LINEAR);  
			string smallPath =filePath+ "\\small\\"+"small"  + *itr;
			cvSaveImage(smallPath.c_str(),imageresize);
			cvReleaseImage(&curImage);
			cvReleaseImage(&imageresize);
		}

	}

}

你可能感兴趣的:(C++,知识点)