/* 写入视频文件 */ /*命令行调用方式: E:\软件编程\毕业设计\OpenCV\exam1\debug > exam1 1.avi 2.avi //exam1为exe文件 1.avi为原视频文件 2.avi 为接收视频文件 */ #include "cv.h" #include "highgui.h"
void exam5( int argc, char** argv ) { //argv[1] = "1.avi"; //argv[2] = "2.avi"; int count = 0; CvCapture* capture = 0; if( argc == 3 ) capture = cvCreateFileCapture( argv[1] ); else return;
if( !capture ) return; IplImage *bgr_frame = cvQueryFrame( capture ); double fps = cvGetCaptureProperty( capture, CV_CAP_PROP_FPS ); CvSize size = cvSize( (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH ), (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT ) ); CvVideoWriter *writer = cvCreateVideoWriter( argv[2], CV_FOURCC( 'M','J','P','G' ), fps, size ); IplImage* logpolar_frame = cvCreateImage( size, IPL_DEPTH_8U, 3 ); while( (bgr_frame=cvQueryFrame(capture)) != NULL ) { count++; if( count%100 == 0 ) printf( "正在提取第%d帧\n",count ); cvLogPolar( bgr_frame, logpolar_frame, cvPoint2D32f( bgr_frame->width/2,bgr_frame->height/2 ), 40, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS ); cvWriteFrame( writer, logpolar_frame ); if( count == 10000 ) break; } cvWaitKey(0); printf( "提取完毕,共%d帧\n",count ); system( "pause" ); cvReleaseVideoWriter( &writer ); cvReleaseImage( &logpolar_frame ); cvReleaseCapture( &capture ); }
int main( int argc, char** argv ){
exam5( argc, argv );
}