During school days when i use OpenCV 1.1-2.0 for my final year project,
I had a hard time trying to capture video frame from .avi files.
I ran into codec issues having to convert my video dataset before i can capture
via OpenCV.
With the following code snippets below i am able to play .avi,.mpg and wmv files!
#include "highgui.h"
int main( int argc, char** argv ) {
//Some validation can be included here for argv
if( argc<2 ) return 1;
CvCapture* capture = cvCreateFileCapture( argv[1] );
if( !capture ) return 1;
/* get fps, needed to set the delay */
int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
IplImage* frame;
cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "video", frame );
char c = cvWaitKey( 1000 / fps );
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "video" );
return 0;
}
No comments:
Post a Comment