开发者

Playing AVI files in OpenCV

I can't seem to play my avi files using OpenCV. I am on a Mac and the files work with Quicktime and VLC player. I have tried using mencoder to convert it to i420 but that still has not been successful. No error messages occur and it seems like the program closes automatically and I'm not sure how to debug it.

int main(int argc, char* argv[]) 
{
    cvNamedWindow( "Example2", CV_WIN开发者_运维知识库DOW_AUTOSIZE );
    CvCapture* capture = cvCreateFileCapture( argv[1] );
    IplImage* frame;
    while(1) {
        frame = cvQueryFrame( capture );
        if( !frame ) break;
        cvShowImage( "Example2", frame );
        char c = cvWaitKey(33);
        if( c == 27 ) break;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( "Example2" );
}


Well, since your code lacks error checking, maybe there was a problem with cvCreateFileCapture() and you'll never know until you check the return of the function.

Anyway, you should either remove, or add a debug for this statement here:

if( !frame ) break;

Becouse if there was a problem retrieving the first frame of the file, your application would simply give up and quit silently, giving you the "nothing happened" feeling.

Changed it to something like:

if (!frame) { printf("Uow, huge fail!\n"); break;}

But most importantly: why are you not using cvCaptureFromAVI() ? Check this out: http://nashruddin.com/How_to_Play_AVI_Files_with_OpenCV

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜