2009-08-31 9 views
3

これは、オライリー学習OpenCVのからコードスニペットですcvGetCapturePropertyは、常にCV_CAP_PROP_FRAME_COUNTに対して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はいつも私がヤフーにOpenCVのグループを検索しました0を返し、同じ問題を発見しました。

答えて

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のインストールを実行した後にインストール1)でこの問題を持っていないようですが、私はOSX上でそれに実行し続けます。私はそれが私が使っていたOpenCVのバージョンとしなければならなかったと思った(私はむしろ、最近のLinuxの1をインストールされている)ので、私は私のMac上のOpenCV 2.2をインストールしたのですが、問題が解消されません。これは、リポジトリの最新バージョンに完全に補正されている場合

誰でも知っていますか?

0

さらに悪いことには、私はWindows 7でこの問題を持っていなかった、そして数日後、私がやった、同じビデオファイルです。韻や理由はありません。