使用OpenCV进行视频捕获的执行错误

时间:2012-12-26 11:39:54

标签: visual-studio-2010 image-processing opencv computer-vision video-capture

执行程序时遇到以下问题。程序在主函数的第1行异常崩溃。这条道路都是正确的,那里没有错。 lib-include的所有设置都完美地完成了。这可能有什么问题?

#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;

}

1 个答案:

答案 0 :(得分:0)

作为一个完整性检查,让我们看看OpenCV C ++ API中的VideoCapture内容是否有效。让我们试一试:

#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

我在这里将C和C ++ OpenCV API混合在一起,但我只是想帮助你让它运行起来。