opencv写入AVI文件[8]

 1 /**
 2 此程序实现读入一个彩色视频文件,写入另一个avi文件
 3 **/
 4 #include <highgui.h>
 5 #include <cv.h>
 6 int main(int argc,char * argv[])
 7 {
 8     CvCapture * capture = cvCreateFileCapture("I:\\资料\\opencv相关资料\\OpenCV教程\\图像与视频\\video.long.mjpg.avi");
 9     //capture =cvCreateFileCapture(argv[1]);
10     if(!capture)
11     {
12         return -1;
13     }
14     IplImage * bgr_frame = cvQueryFrame(capture);
15     double fps = cvGetCaptureProperty(capture,CV_CAP_PROP_FPS);
16     CvSize size = cvSize((int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH),(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT)); 
17     CvVideoWriter * writer = cvCreateVideoWriter("out-avi",CV_FOURCC('M','J','P','G'),fps,size);
18     IplImage * logpolar_frame = cvCreateImage(size,IPL_DEPTH_8U,3);
19     while((bgr_frame=cvQueryFrame(capture))!= NULL)
20     {
21         ////以图像中心位原点,缩放比例40,双线性插值,空白部分填充黑色。
22         //cvLogPolar(bgr_frame,logpolar_frame,cvPoint2D32f(bgr_frame->width/2,bgr_frame->height/2),40,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
23         cvWriteFrame(writer,logpolar_frame);
24 
25         logpolar_frame = cvQueryFrame(capture);
26         if(!logpolar_frame)break;
27         cvShowImage("example",logpolar_frame);
28         char c = cvWaitKey(33);
29         if(c==27) break;
30     }
31     cvNamedWindow("example",CV_WINDOW_AUTOSIZE);
32     cvWaitKey(0);
33     cvReleaseVideoWriter(&writer);
34     cvReleaseImage(&logpolar_frame);
35     cvReleaseCapture(&capture);
36     return 0;
37 }

 

posted on 2013-02-28 16:03  0fengfan0  阅读(1246)  评论(0编辑  收藏  举报

导航