-------------------------------------------------------------------------------------------------------------------------------
图片批量处理
SkySeraph July 4th 2011 HQU
Email:zgzhaobo@gmail.com QQ:452728574
Latest Modified Date:July 4th 2011 HQU
-------------------------------------------------------------------------------------------------------------------------------
批量处理文件夹下所有的图片,以彩色图像灰度化为例,直接添代码:
int main(int argc,char** argv) { WIN32_FIND_DATAA FileData; HANDLE hFind; hFind = FindFirstFileA((LPCSTR)"Imgs/*.jpg",&FileData); if (hFind == INVALID_HANDLE_VALUE) { printf ("Invalid File Handle. GetLastError reports %d\n", GetLastError ()); return 0; } while (FindNextFileA(hFind, &FileData)) { cout<<FileData.cFileName<<endl; string name("Imgs/"); name.append(FileData.cFileName); IplImage* src=cvLoadImage(name.c_str()); if (!src) { cout<<"failed to load image"<<endl; //API //AfxMessageBox("failed to load image"); //MFC break; } assert(src->nChannels==3); // 处理 IplImage* srcGray = cvCreateImage(cvGetSize(src),IPL_DEPTH_8U,1); cvCvtColor(src,srcGray,CV_BGR2GRAY); // 保存 name.append(".srcGray.jpg"); cvSaveImage(name.c_str(),srcGray); cvReleaseImage(&src); cvReleaseImage(&srcGray); } FindClose(&hFind); return 0; }
效果(省)
-------------------------------------------------------------------------------------------------------------------------------
对比参考:
如何批量处理一个文件夹的图片文件 http://www.opencv.org.cn/forum/viewtopic.php?t=12510
遍历读取指定文件夹下指定类型的所有文件 http://blog.csdn.net/carson2005/archive/2011/03/31/6292726.aspx
http://hi.baidu.com/yibobin/blog/item/c43e6801c7a10e111c95830d.html 图片批量归一化处理
http://www.doc88.com/p-91973419874.html 如何用VC++实现文件的批量处理
http://hi.baidu.com/%B9%C2%D6%DB%B5%F6%BF%CD/blog/item/d69f91c5e1f0ed029d163dc8.html
opencv 图片实现格式转换,并使用批处理实现批量转换
-------------------------------------------------------------------------------------------------------------------------------
Author: SKySeraph
Email/GTalk: zgzhaobo@gmail.com QQ:452728574
From: http://www.cnblogs.com/skyseraph/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
-------------------------------------------------------------------------------------------------------------------------------