简体   繁体   English

使用OpenCV进行视频捕获时发生执行错误

[英]Execution Error using OpenCV for video Capturing

I am facing the following problem when I execute the programme. 执行程序时,我面临以下问题。 The program crashed abnormally at line no 1 of the main function. 程序在主功能的第1行异常崩溃。 the path of the is all correct, nothing is wrong there. 的路径都是正确的,那里没有错。 All set-up of the lib-include additional libraries are done perfectly. lib-include附加库的所有设置都完美完成。 What could be wrong here? 这有什么问题吗?

#include <cv.h>
#include <highgui.h>

int main()
{
     //load the video file to the memory
   **  CvCapture *capture =     cvCaptureFromAVI("A.avi"); ** // this instruction crashed the file is there in the folder, that not an issue....

     if( !capture ) return 1;

     //obtain the frames per seconds of that video
     int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );

    //create a window with the title "Video"
    cvNamedWindow("Video");

    while(true) {
             //grab and retrieve each frames of the video sequencially 
             IplImage* frame = cvQueryFrame( capture );

             if( !frame ) break;

             //show the retrieved frame in the "Video" window
             cvShowImage( "Video", frame );

             int c; 


             if(fps!=0){  

                     //wait for 1000/fps milliseconds
                     c = cvWaitKey(1000/fps);
            }else{
                     //wait for 40 milliseconds
                      c = cvWaitKey(40);
            } 



          //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27) 
            if((char)c==27 ) break;
   }

   //destroy the opened window
   cvDestroyWindow("Video");   
   //release memory
   cvReleaseCapture( &capture );

    return 0;

}

As a sanity check, let's see if the VideoCapture stuff from the OpenCV C++ API works. 作为一个健全性检查,让我们看看OpenCV C ++ API中的VideoCapture东西是否有效。 Let's give this a try: 让我们尝试一下:

#include <opencv2/opencv.hpp>
#include <cv.h>
using namespace cv;

VideoCapture capture("A.avi");
Mat matFrame;
capture >> matFrame; //each time you do this, the next video frame goes into the 'matFrame' object        
IplImage* frame=cvCloneImage(&(IplImage)matFrame); //convert Mat to IplImage to hook in with your code

I'm mixing the C and C++ OpenCV APIs together here, but I just wanted to help you get it running. 我在这里混合使用C和C ++ OpenCV API,但我只是想帮助您使其运行。

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

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