18

How to set Camera FPS?

May be cvSetCaptureProperty(cameraCapture, CV_CAP_PROP_FPS, 30); ?

But it's return HIGHGUI ERROR: V4L2: Unable to get property (5) - Invalid argument

Because there is no implementation in 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;
}

How to solve it?

4 Answers 4

20

using the python wrappers for opencv, it worked for me to refer to the variable as:

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

I am using python 2.7.3 and opencv 2.4.8

The camera is the PS3 Eye

3
  • 8
    I am using python 3.5.2 and ps3 eye and opencv 3.2.0-dev and linux and this method works for me. The name of the constant seems to have changed to just CAP_PROP_FPS though. Mar 29, 2017 at 1:55
  • You can set it to 187 fps too :D (if low-res 320x240 set via CAP_PROP_FRAME_WIDTH/HEIGHT) Mar 29, 2017 at 2:10
  • 4
    On OpenCV 3.4.3 (Python 2.7), the property seems to be cv2.CAP_PROP_FPS (no .cv needed). Jan 31, 2019 at 22:51
6

I don't know if that's still valid, but some time ago, something like one year and a half, I encountered that exactly problem. I contacted with a developer of OpenCV and he told me that the access and ability to change some of the properties of a capture weren't implemented yet and some other just worked for certain kinds of camera. I finally took a look to libdc1394 (working in linux) and made some functions that converted the data retrieved by libdc1394 to IplImages from OpenCV. It wasn't a such a tough task.

3
  • I definetly is true that not all cameras support all Operations. Feb 13, 2014 at 13:36
  • I never said that, I only told my experience and how I solved a similar problem.
    – Genís
    Feb 13, 2014 at 14:10
  • That is true, but i have a Logitech c920 and that camera just doesn't supports all operations. I just wanted to support your claim "other just worked for certain kinds of camera" :), related stackoverflow.com/questions/16432676/… Feb 13, 2014 at 14:47
6

CV_CAP_PROP_FPS is a NOT a fake. See cap_libv4l.cpp(1) in OpenCV github repo. The key is to make sure, you use libv4l over v4l while configuring OpenCV. For that, before running cmake, install libv4l-dev

sudo apt-get install libv4l-dev

Now while configuring OpenCV with cmake, enable option, WITH_LIBV4L. If all goes good, in configuration status, you will see some thing similar to below

V4L/V4L2: Using libv4l1 (ver ) / libv4l2 (ver )

And then while building your OpenCV code, you will have to link with libv4l1/libv4l2/libv4lconvert.

Arbitary FPS values at the resolutions you choose, needn't be supported by your webcam. You may check supported resolutions/fps with a graphical tools like cheese or commands like lsusb (2)

3
  • 1
    Worked for me for OpenCV 3.0.0 on Ubuntu 12.04. After installing libv4l-dev, I reran my original cmake (WITH_LIBV4L was enabled by default) and linking worked without any change to make. Getting and setting CV_CAP_PROP_FPS now works for my LifeCam Cinemas. Aug 19, 2015 at 14:36
  • 1
    v4l2-ctl -d 0 --list-formats-ext lists the supported frame rates for each pixel format (e.g., 'MJPG') and resolution. For my LifeCam Cinemas, MJPG, and 640x480, I could set 30fps but measured only 15fps in my OpenCV "camera viewer" code. Aug 19, 2015 at 14:50
  • Which also means that it may not work in some already compiled versions, or on different platforms (like windows). Jan 16, 2018 at 21:31
3

check opencv2.4 handbook out, the video capture thing is much better than before,

->set(CV_CAP_PROP_FPS,30);works for me most of the times. but a little bit low efficiency.

just in case you might not like the new opencv2.4 and still want to control your camera. check the videoinput lib here. it works good and using directshow features. http://www.aishack.in/2010/03/capturing-images-with-directx/ http://www.muonics.net/school/spring05/videoInput/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.