2011-12-02 62 views
0

我買了OpenCV書籍,第一個視頻程序無法正常工作。在繼續之前,我想知道我的系統中是否有問題。這是一個非常簡單的程序,很少需要調試。'Hello world'video program not working

#include "highgui.h" 

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"); 
} 

它編譯通常,但運行時,程序只是打開一個白色的窗口幾秒鐘,然後關閉。顯然,沒有任何錯誤,看起來像是一個貶低警告。什麼可能是錯的?

k♥t ./demo /opt/Media/Vídeos/Docs/Connections/Connections/02\ -\ Death\ in\ the\ Morning.avi 
Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. 
k♥t 

編輯:對不起,所有的大驚小怪,這只是一個錯字。現在修好了。

+0

您使用的是什麼版本的OpenCV?什麼OS?什麼IDE /構建環境? – mevatron

回答

1

我看到很多文件名中的空格作爲參數傳遞,並且您有混合正向和反向斜線。請驗證路徑和文件名是否有效。

1

添加安全檢查!始終驗證您所撥打的功能是否成功:

CvCapture* capture = cvCreateFileCapture(argv[1]); 
if (!capture) 
{ 
    // Print error message! Failed to load file 
} 

可能是因爲它無法加載文件。