Learning OpenCV Capture 2

3. 4. 5. //实现摄像机视频数据缩放显示,同时存入磁盘,可以动态的调节缩放比例。 #include "cv.h" #include "highgui.h" #include <stdio.h> int g_slider_position = 0; IplImage* doPyrDown(IplImage* in,int filter = IPL_GAUSSIAN_5x5) { // Best to make sure input image is divisible by two. // assert( in->width%2 == 0 && in->height%2 == 0 ); IplImage* out = cvCreateImage( cvSize( in->width/2, in->height/2 ), in->depth, in->nChannels ); out->origin = 1; cvPyrDown( in, out ); return( out ); }; main( int argc, char* argv[] ) { cvNamedWindow( "Source", CV_WINDOW_AUTOSIZE ); cvNamedWindow( "Result", CV_WINDOW_AUTOSIZE ); CvCapture* capture = cvCreateCameraCapture( -1 ); if (!capture){ return -1; } IplImage* pFrame; IplImage* pyr_frame; 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( "video.avi", CV_FOURCC('P','I','M','1'), fps, size ); cvCreateTrackbar( "Position", "Result", &g_slider_position, 8, NULL ); while(1) { pFrame=cvQueryFrame(capture); pyr_frame = cvCreateImage( cvSize( pFrame->width/2, pFrame->height/2 ), pFrame->depth, pFrame->nChannels ); switch (g_slider_position) { case 2: pyr_frame = doPyrDown(pFrame); break; case 4: pyr_frame = doPyrDown(pFrame); pyr_frame = doPyrDown(pyr_frame); break; case 8: pyr_frame = doPyrDown(pFrame); pyr_frame = doPyrDown(pyr_frame); pyr_frame = doPyrDown(pyr_frame); break; default: pyr_frame = cvCloneImage(pFrame);; } cvShowImage( "Source", pFrame ); cvShowImage( "Result", pyr_frame ); cvWriteToAVI( writer, pyr_frame ); char c = cvWaitKey(10); if( c == 27 ) break; } cvReleaseVideoWriter( &writer ); cvReleaseImage( &pyr_frame ); cvReleaseCapture( &capture ); cvDestroyWindow("Source"); cvDestroyWindow("Result"); }

OpenCV 1.0存视频文件有问题,2.0解决了这个问题。

你可能感兴趣的:(c,image,filter,null,input,磁盘)