对于CV_CAP_PROP_FRAME_COUNT,cvGetCaptureProperty始终返回0! [英] cvGetCaptureProperty always return 0 for CV_CAP_PROP_FRAME_COUNT!

查看:571
本文介绍了对于CV_CAP_PROP_FRAME_COUNT,cvGetCaptureProperty始终返回0!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is a code snippet from 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组,发现了同样的问题.

But unfortunately, cvGetCaptureProperty always return 0. I have searched opencv group in Yahoo, found the same problem.

推荐答案

哦,我明白了.我已经在学习OpenCV的示例代码中找到了以下代码片段:

Oh, I get it. I have found these code snippet in the Learning OpenCV's samples codes:

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

这篇关于对于CV_CAP_PROP_FRAME_COUNT,cvGetCaptureProperty始终返回0!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆