OPENCV 轉換圖片為指定格式,opencv圖片
// TrainingFaceSegment.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include<windows.h>#include<iostream>#include<string>#include "cv.h" #include "highgui.h" IplImage* img;IplImage* resizeImg;void find(char * lpPath){char szFile[MAX_PATH] = {0};char szFind[MAX_PATH];char root[MAX_PATH];WIN32_FIND_DATA FindFileData;strcpy(szFind,lpPath);strcat(szFind,"*.*");HANDLE hFind=::FindFirstFile(szFind,&FindFileData);if(INVALID_HANDLE_VALUE == hFind) return;while(TRUE){if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){if(FindFileData.cFileName[0]!='.'){strcpy(szFile,lpPath);strcat(szFile,FindFileData.cFileName);strcat(szFile,"//");find(szFile);}}else{strcpy(root, lpPath);strcat(root,FindFileData.cFileName);img = cvLoadImage(root);strcpy(root, "..//..//images2//");strcat(root,FindFileData.cFileName);cvSaveImage(root,img);cvReleaseImage(&img);}if(!FindNextFile(hFind,&FindFileData)) break;}FindClose(hFind);}void main(){find("..//..//images//");getchar();}
strcat(root,FindFileData.cFileName);
把上面這句話的cFileName改成自己想要的格式如jpg.bmp即可