在OpenCV中播放AVI文件 [英] Playing AVI files in OpenCV

查看:131
本文介绍了在OpenCV中播放AVI文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法使用OpenCV播放我的avi文件。我在Mac和文件工作与Quicktime和VLC播放器。我已经尝试使用mencoder来将其转换为i420,但仍然没有成功。没有错误消息,似乎程序自动关闭,我不知道如何调试它。

  int main(int argc,char * argv [])
{
cvNamedWindow(Example2 ,CV_WINDOW_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);
}


解决方案

错误检查,也许cvCreateFileCapture()有一个问题,你永远不会知道,直到你检查函数的返回。



无论如何,你应该删除,为此语句添加调试:

  if(!frame) 

如果检索文件的第一帧时出现问题,您的应用程序将会放弃



更改为:

  if(!frame){printf(Uow,huge fail!\\\
);但最重要的是:你为什么不使用cvCaptureFromAVI()?
查看: http://nashruddin.com/How_to_Play_AVI_Files_with_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_WINDOW_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

这篇关于在OpenCV中播放AVI文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆