opencv 的图片导入(cvLoadImage)和保存图片(cvSaveImage)分别支持很多格式的图片,但是他们在内存在却是统一的结构( IplImage),所以我们可以很轻松的实现图片格式的转换,代码很简单
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include<stdlib.h>
int main(int argc,char * argv[])
{
IplImage* img = 0;
img = cvLoadImage(argv[1],CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
cvNamedWindow("region of image",CV_WINDOW_AUTOSIZE);
cvShowImage("region of image",img);
int num=strlen(argv[1]);
char* name=new char[num+1];
strcpy(name,argv[1]);
*(name+num-1)='p';
*(name+num-2)='m';
*(name+num-3)='b';
*(name+num)='\0';
cvSaveImage(name,img);
cvWaitKey(0);
return 0;
}
文章来源https://blog.csdn.net/dvstream/article/details/7452946