简体   繁体   English

在opencv中显示文件中的视频

[英]show a video from a file in opencv

I am trying to open a video (.avi) from a file, read frame by frame and show them in a window. 我正在尝试从文件中打开视频(.avi),逐帧读取并将其显示在窗口中。 I have looked here in stack overflow and found some interesting codes, but every one of them keeps blowing up my program and I don't know why. 我在堆栈溢出中查看了一下,发现了一些有趣的代码,但是每个代码都使我的程序崩溃,我也不知道为什么。 I used this code: 我使用以下代码:

 int main( int argc, const char** argv ) {

    CvCapture* capture = 0;
    string inputName = "C:\\Users\\Cristina\\Videos\\Capture_me.avi";

    capture = cvCaptureFromAVI( inputName.c_str() );

    if( !capture ) {

        cout << "Capture from AVI didn't work" << endl;

    } else {

         cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
         cout << "In capture ..." << endl;

         IplImage* currFrame = cvQueryFrame( capture );
         IplImage* prevFrame = cvCloneImage( currFrame );

    while( currFrame = cvQueryFrame( capture ) ) {

          if( !currFrame )

             break;

          cvShowImage( "result", currFrame );
          cvCopy( currFrame , prevFrame );

    }

        waitKey(0);

        cvReleaseCapture( &capture );
        cvReleaseImage( &currFrame );
        cvDestroyWindow( "result" );

    }

    return 0;
}

The while loop condition throws: Unhandled exception at 0x0000000066E538C6 (opencv_ffmpeg245_64.dll) in FaceDetection.exe: 0xC0000005: Access violation reading location 0x0000000002EF1000. while循环条件抛出:FaceDetection.exe中0x0000000066E538C6(opencv_ffmpeg245_64.dll)的未处理异常:0xC0000005:访问冲突读取位置0x0000000002EF1000。

I also tried the same program but with this loop: 我也尝试了相同的程序,但是有这个循环:

while( cvGrabFrame( capture ) ) {

        if( !currFrame )

            break;

        cvShowImage( "result", currFrame );
        cvCopy( currFrame, prevFrame );  
        currFrame = cvRetrieveFrame( capture );

    }

This second while loop condition throws the same exception at "currFrame = cvRetrieveFrame( capture );" 第二个while循环条件在“ currFrame = cvRetrieveFrame(capture);”处引发相同的异常。 : Unhandled exception at 0x0000000066E538C6 (opencv_ffmpeg245_64.dll) in FaceDetection.exe: 0xC0000005: Access violation reading location 0x0000000003011000. :FaceDetection.exe中0x0000000066E538C6(opencv_ffmpeg245_64.dll)处未处理的异常:0xC0000005:访问冲突读取位置0x0000000003011000。

Can someone please help me understand what is wrong with these codes and how do I fix them? 有人可以帮我理解这些代码有什么问题,以及如何解决这些问题吗? Thanks!! 谢谢!!

I think this is a similar question Unhandled exception at 0x10012c5d (highgui110.dll) . 我认为这是0x10012c5d(highgui110.dll)的类似问题未处理异常 The main point being that you might be using an unstable version of OpenCV which might have linking problems. 重点是您可能使用的是不稳定版本的OpenCV,该版本可能存在链接问题。 Try reverting back to the previous version of OpenCV and see if it works or not. 尝试恢复到以前的OpenCV版本,看看它是否有效。 Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM