3

これは、O'ReillyLearningOpencvのコードスニペットです。

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

わかりました。LearningOpenCVのサンプルコードで次のコードスニペットを見つけました。

/*
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 に答える