2009-08-31 70 views
3

這是來自O'Reilly的opencv學習的代碼片段,對於CV_CAP_PROP_FRAME_COUNT,cvGetCaptureProperty始終返回0!

cvNamedWindow("Example3", CV_WINDOW_AUTOSIZE); 
g_capture = cvCreateFileCapture(argv[1]); 
int frames = (int) cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT); 
if (frames != 0) { 
    cvCreateTrackbar("Position", "Example3", &g_slider_postion, frames, onTrackbarSlide); 
} 

但不幸的是,cvGetCaptureProperty始終返回0找遍了OpenCV的組中的雅虎,發現了同樣的問題。

回答

4

哦,我明白了。我在學習OpenCV的示例代碼中發現了這些代碼片段:

/* 
OK, you caught us. Video playback under linux is still just bad. Part of this is due to FFMPEG, part of this 
is due to lack of standards in video files. But the position slider here will often not work. We tried to at least 
find number of frames using the "getAVIFrames" hack below. Terrible. But, this file shows something of how to 
put a slider up and play with it. Sorry. 
*/ 
//Hack because sometimes the number of frames in a video is not accessible. 
//Probably delete this on Widows 
int getAVIFrames(char * fname) { 
    char tempSize[4]; 
    // Trying to open the video file 
    ifstream videoFile(fname , ios::in | ios::binary); 
    // Checking the availablity of the file 
    if (!videoFile) { 
     cout << "Couldn’t open the input file " << fname << endl; 
     exit(1); 
    } 
    // get the number of frames 
    videoFile.seekg(0x30 , ios::beg); 
    videoFile.read(tempSize , 4); 
    int frames = (unsigned char) tempSize[0] + 0x100*(unsigned char) tempSize[1] + 0x10000*(unsigned char) tempSize[2] + 0x1000000*(unsigned char) tempSize[3]; 
    videoFile.close(); 
    return frames; 
} 
1

我有同樣的問題。它說它可以在Windows上工作,但它不會。我想這是因爲我使用Dev-C++和Dev-C++使用gcc。雖然我不確定這是否是原因。

0

我似乎沒有在Linux版本(執行ROS安裝後安裝的版本)有這個問題,但我一直在OSX上運行它。我認爲這與我使用的OpenCV版本有關(我最近安裝了Linux版本),所以我在我的Mac上安裝了OpenCV 2.2,但問題仍然存在。

有誰知道這是否已完全更正了最新版本的存儲庫?

0

更糟糕的是,我沒有在Windows 7上的這個問題,然後幾天後,我用相同的視頻文件。沒有韻或理由。