Ask Your Question
1

How do I adjust FPS for a v4l2 camera

asked 2013-02-13 01:49:59 -0600

Anders Musikka gravatar image

updated 2013-02-14 00:38:51 -0600

How can I adjust the FPS that my v4l2 camera captures at?

The following patch seems to solve it, but is there any other way?

From 0ad873a3682a1d7354b8c233e71fc76c7bb319b1 Mon Sep 17 00:00:00 2001 From: Anders Musikka [email protected] Date: Wed, 13 Feb 2013 08:45:04 +0100 Subject: [PATCH] Add FPS adjust possibility

---
 modules/highgui/src/cap_libv4l.cpp |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/modules/highgui/src/cap_libv4l.cpp b/modules/highgui/src/cap_libv4l.cpp
index 63a2ff9..179c90f 100644
--- a/modules/highgui/src/cap_libv4l.cpp
+++ b/modules/highgui/src/cap_libv4l.cpp
@@ -1665,6 +1665,22 @@ static int icvSetPropertyCAM_V4L(CvCaptureCAM_V4L* capture, int property_id, dou
             width = height = 0;
         }
         break;
+    case CV_CAP_PROP_FPS:
+    {
+        struct v4l2_streamparm streamparm;
+        struct v4l2_fract *tpf;
+        memset (&streamparm, 0, sizeof (streamparm));
+        streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+        tpf = &streamparm.parm.capture.timeperframe;
+        tpf->numerator = 1;
+        tpf->denominator = cvRound(value);
+        retval=1;
+        if (ioctl(capture->deviceHandle, VIDIOC_S_PARM, &streamparm) < 0) {
+            fprintf(stderr,"Failed to set camera FPS: %s\n",strerror(errno));
+            retval=0;
+        }
+        break;
+    }
     default:
         retval = icvSetControl(capture, property_id, value);
     }
-- 
1.7.9.5
edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-14 01:04:33 -0600

CV_CAP_PROP_FPS is not implemented for V4L back-end. OpenCV is open source project and you can contribute to it. The best solution is pull request using Github facilities. Just fork official OpenCV Github repository, make changes and send pull request.

edit flag offensive delete link more
0

answered 2013-08-19 03:31:44 -0600

appu gravatar image

Hi i added the above code in cap_libv4l.cpp. But it's not effecting my frame rate. can you tell me any other solution to this?

edit flag offensive delete link more
-1

answered 2013-02-13 01:57:23 -0600

To specify the FPS of your camera you can use VideoCapture::set with the flag CV_CAP_PROP_FPS.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-13 01:49:59 -0600

Seen: 7,585 times

Last updated: Aug 19 '13