【问题标题】:cvGetCaptureProperty always return 0 for CV_CAP_PROP_FRAME_COUNT!cvGetCaptureProperty 总是为 CV_CAP_PROP_FRAME_COUNT 返回 0!
【发布时间】:2010-11-24 07:12:57
【问题描述】:

这是来自 O'Reilly Learning Opencv 的代码 sn-p,

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 组,发现同样的问题。

【问题讨论】:

    标签: opencv


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          【解决方案4】:

          哦,我明白了。我在 Learning OpenCV 的示例代码中找到了这些代码 sn-p:

          /*
          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;
          }
          

          【讨论】:

            猜你喜欢
            • 2021-01-24
            • 1970-01-01
            • 2015-09-27
            • 2014-03-20
            • 2013-04-13
            • 2013-03-30
            • 2016-07-13
            • 2023-04-09
            • 2021-10-27
            相关资源
            最近更新 更多