Thursday, December 23, 2010

Load a Video in OpenCV


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include<opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>

int main(int argc, char *argv[])
{
IplImage *frame;
int key = 'a';
/* supply the AVI file to play */
if(argc<2){
printf("Usage: main <video-file-name>.avi\n\7");
exit(0);
}

/* load the AVI file */
CvCapture *capture = cvCaptureFromAVI( argv[1] );
/* always check */
if( !capture ) return 1;

/* get fps, needed to set the delay */
int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
/* display video */
cvNamedWindow( "video", 0 );
while( key != 'q' ) {

/* get a frame */
frame = cvQueryFrame( capture );
/* always check */

if( !frame ) break;
/* display frame */
cvShowImage( "video", frame );
/* quit if user press 'q' */
cvWaitKey( 1000 / fps );
}

/* free memory */
cvReleaseCapture( &capture );
cvDestroyWindow( "video" );
return 0;
}

To Run Main write the filename.extension in the arguments. make sure that the AVI file is in RAW VIDEO form. see this link for conversion using FFMPEG the same process works for OPEN


Update:
http://opencv.willowgarage.com/wiki/VideoCodecs

using command line tool mencoder
mencoder.exe testReal.avi -ovc raw -vf format=i420 -o out.avi -nosound

No comments:

Post a Comment