Reading Avi File in OpenCV

Playing a video with OpenCV is almost as easy as displaying a single picture. Th e only newissue we face is that we need some kind of loop to read each frame in sequence; we may also need some way to get out of that loop if the movie is too boring.


#include "highgui.h"
int main( int argc, char** argv ) 
	cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
	CvCapture* capture = cvCreateFileCapture("megamind.avi");
	IplImage* frame;
		frame = cvQueryFrame( capture );
		if( !frame ) break;
		cvShowImage( "Example2", frame );
		char c = cvWaitKey(33);
		if( c == 27 ) break;
	cvReleaseCapture( &capture );
	cvDestroyWindow( "Example2" );