如何在OpenCV中设置相机FPS? CV_CAP_PROP_FPS是假的

问题描述 投票:15回答:4

如何设置相机FPS?

可能是cvSetCaptureProperty(cameraCapture,CV_CAP_PROP_FPS,30); ?

但它返回HIGHGUI ERROR:V4L2:无法获取属性(5) - 参数无效

因为highgui / cap_v4l.cpp中没有实现

static int icvSetPropertyCAM_V4L( CvCaptureCAM_V4L* capture,
                                  int property_id, double value ){
    static int width = 0, height = 0;
    int retval;

    /* initialization */
    retval = 0;

    /* two subsequent calls setting WIDTH and HEIGHT will change
       the video size */
    /* the first one will return an error, though. */

    switch (property_id) {
    case CV_CAP_PROP_FRAME_WIDTH:
        width = cvRound(value);
        if(width !=0 && height != 0) {
            retval = icvSetVideoSize( capture, width, height);
            width = height = 0;
        }
        break;
    case CV_CAP_PROP_FRAME_HEIGHT:
        height = cvRound(value);
        if(width !=0 && height != 0) {
            retval = icvSetVideoSize( capture, width, height);
            width = height = 0;
        }
        break;
    case CV_CAP_PROP_BRIGHTNESS:
    case CV_CAP_PROP_CONTRAST:
    case CV_CAP_PROP_SATURATION:
    case CV_CAP_PROP_HUE:
    case CV_CAP_PROP_GAIN:
    case CV_CAP_PROP_EXPOSURE:
        retval = icvSetControl(capture, property_id, value);
        break;
    default:
        fprintf(stderr,
                "HIGHGUI ERROR: V4L: setting property #%d is not supported\n",
                property_id);
    }

    /* return the the status */
    return retval;
}

怎么解决?

opencv camera frame-rate
4个回答
17
投票

使用opencv的python包装器,我可以将变量称为:

cap = cv2.VideoCapture(1)
cap.set(cv2.cv.CV_CAP_PROP_FPS, 60)

我使用的是python 2.7.3和opencv 2.4.8

相机是PS3 Eye


6
投票

我不知道这是否仍然有效,但不久前,就像一年半的时间,我遇到了这个问题。我联系了OpenCV的开发人员,他告诉我,改变捕获的一些属性的访问和能力尚未实现,而其他一些只适用于某些类型的相机。我终于看了一下 libdc1394 (在linux上工作)并制作了一些函数,将libdc1394检索到的数据从OpenCV转换为IplImages。这不是一项艰巨的任务。


6
投票

CV_CAP_PROP_FPS不是假的。请参阅OpenCV github repo中的cap_libv4l.cpp(1)。关键是要确保在配置OpenCV时使用libv4l over v4l。为此,在运行cmake之前,请安装libv4l-dev

sudo apt-get install libv4l-dev

现在,在使用cmake配置OpenCV时,启用选项WITH_LIBV4L。如果一切顺利,在配置状态下,您将看到类似于下面的内容

V4L / V4L2:使用libv4l1(ver)/ libv4l2(ver)

然后在构建OpenCV代码时,您必须链接libv4l1 / libv4l2 / libv4lconvert。

您选择的分辨率下的任意FPS值不需要您的网络摄像头支持。您可以使用图形工具(如奶酪)或lsusb(qazxsw poi)等命令检查支持的分辨率/ fps


3
投票

检查一下opencv2.4手册,视频捕捉的事情比以前好多了,

- > set(CV_CAP_PROP_FPS,30);大部分时间都适合我。但效率有点低。

以防您可能不喜欢新的opencv2.4,但仍想控制您的相机。在这里查看videoinput lib。它运作良好并使用directshow功能。 2 http://www.muonics.net/school/spring05/videoInput/

© www.soinside.com 2019 - 2024. All rights reserved.