3

这是来自 O'Reilly Learning Opencv 的代码片段,

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。我在 Yahoo 中搜索了 opencv 组,发现了同样的问题。

4

4 回答 4

4

哦,我明白了。我在 Learning 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;
}
于 2009-09-07T00:57:43.843 回答
1

我有同样的问题。它说它可以在 Windows 上工作,但事实并非如此。我想这是因为我使用 Dev-C++ 而 Dev-C++ 使用 gcc。虽然我不确定这是否是原因。

于 2010-12-20T05:20:10.813 回答
0

更糟糕的是我在 Windows 7 上没有这个问题,然后几天后我用相同的视频文件遇到了这个问题。没有押韵或理由。

于 2012-03-11T18:55:00.330 回答
0

我在 linux 版本中似乎没有这个问题(在安装 ROS 后安装的那个),但我在 OSX 上一直遇到这个问题。我认为这与我使用的 OpenCV 版本有关(我最近安装了 linux 版本)所以我在我的 Mac 上安装了 OpenCV 2.2,但问题仍然存在。

有谁知道这是否已在最新版本的存储库中完全纠正?

于 2011-02-01T02:14:48.933 回答