文件的保存
- /* 功能:图像格式的转换,学习文件的保存
- */
- #include "stdafx.h"
- #include <cv.h>
- #include <highgui.h>
- #include <stdio.h>
- int main( int argc, char** argv )
- {
- IplImage* src;
- // -1: the loaded image will be loaded as is (with number of channels depends on the file).
- if(argc != 3)
- {
- printf("CONV: Image format convertion, support JPG,BMP,TIF,PNG,PPM/n");
- printf("Usage: conv srcImage dstImage/n");
- return 0;
- }
- if( ( strstr(argv[1],".jpg")==NULL
- && strstr(argv[1],".bmp")==NULL
- && strstr(argv[1],".tif")==NULL
- && strstr(argv[1],".png")==NULL
- && strstr(argv[1],".ppm")==NULL )
- || ( strstr(argv[2],".jpg")==NULL
- && strstr(argv[2],".bmp")==NULL
- && strstr(argv[2],".tif")==NULL
- && strstr(argv[2],".png")==NULL
- && strstr(argv[2],".ppm")==NULL ))
- {
- printf("WARNING: CONV only support JPG,BMP,TIF,PPM,TGA and PPM/n");
- }
- else {
- if( (src=cvLoadImage(argv[1], -1))!= 0 ) {
- cvSaveImage( argv[2], src);
- cvReleaseImage(&src);
- printf("/n Convert successfully./n");
- }
- else
- {
- printf("/n*** Read or write image fails *** /n");
- }
- }
- return 0;
- }
- //cvSaveImage
- //
- //保存图像到文件
- //需要include "highgui.h"
- //int cvSaveImage( const char* filename, const CvArr* image );
- //filename
- //文件名,如果对应的文件已经存在,则将被覆盖。
- //image
- //要保存的图像。
- //函数cvSaveImage保存图像到指定文件。
- //图像格式的的选择依赖于filename的扩展名,
- //请参考cvLoadImage。只有8位单通道或者3通道(通道顺序为'BGR' )
- //可以使用这个函数保存。如果格式,深度或者通道不符合要求,
- //请先用cvCvtScale 和cvCvtColor转换;
- //或者使用通用的cvSave保存图像为XML或者YAML格式。