I'm trying my hand at OpenCV and have run into a problem that Dr. Google hasn't been able to help me out with. According to O'Reilly, the following code should play an AVI file in a window the program creates.
#include "highgui.h"
#include <stdio.h>
int main( int argc, char** argv ){
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( argv[1] );
IplImage* frame;
printf("Starting loop\n");
while(1){
frame = cvQueryFrame( capture );
if( !frame ){
printf("Breaking: No frame\n");
break;
}
cvShowImage( "Example2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}
But, when I compile using the latest OpenCV libraries I always fall into the !frame. The references for OpenCV say that cvQueryFrame will return NULL on error - but they're not really specific as to what conditions will cause an error. I'm passing in the name of 19-sec AVI clip as the target file, but I never seem to grab a frame.
(running a 'file' on my AVI gives this as the file type: RIFF (little-endian) data, AVI, 640 x 480, 30.00 fps, video:, audio: uncompressed PCM (mono, 44100 Hz)). I don't think my AVI file is not messed up because totem can play it. I just can't find any information as to what causes cvQueryFrame to error and quit.
Can anybody shed some light on to why my code is failing? Or point me to any information that gives more details about reading AVI data?
P.S. - The code snippet is from "Learning OpenCV Computer Vision with the OpenCV Library", 2008. I've also read through the capture methods from opencv.willowgarage.com - but there's just not a lot of information.
The program is built on an Ubuntu 10.04 system with GCC 4.4.3, linked against the OpenCV 2.3.1a libraries.