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?

karlphillip
  • 92,053
  • 36
  • 243
  • 426
victor1234
  • 871
  • 3
  • 12
  • 28

4 Answers4

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

elzbth
  • 201
  • 2
  • 2
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)

Community
  • 1
  • 1
kiranpradeep
  • 10,859
  • 4
  • 50
  • 82
  • 1
    Worked for me for OpenCV 3.0.0 on Ubuntu 12.04. After installing libv4l-dev, I reran my [original cmake](http://stackoverflow.com/a/29238291/1628638) (`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. – Ulrich Stern Aug 19 '15 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. – Ulrich Stern Aug 19 '15 at 14:50
  • Which also means that it may not work in some already compiled versions, or on different platforms (like windows). – Tomasz Gandor Jan 16 '18 at 21:31
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.

Genís
  • 1,468
  • 2
  • 13
  • 24
  • I definetly is true that not all cameras support all Operations. – Sebastian Schmitz Feb 13 '14 at 13:36
  • I never said that, I only told my experience and how I solved a similar problem. – Genís Feb 13 '14 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 http://stackoverflow.com/questions/16432676/cant-access-properties-of-cvvideocapture-with-logitech-c920 – Sebastian Schmitz Feb 13 '14 at 14:47
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/

flankechen
  • 1,225
  • 16
  • 31