0

我在執行程序時遇到以下問題。該程序在主函數的第一行異常崩潰。這條路是完全正確的,沒有什麼是錯的。所有lib-include附加庫的設置都完美無缺。這裏有什麼可能是錯的?使用OpenCV進行視頻捕獲時的執行錯誤

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

} 
+0

這裏是相關的程序 –

+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++的API OpenCV的,但我只是想幫助你得到它運行。