1
votes

cv2 can not set the fps but I can change the fps with ;

v4l2-ctl -d 1 --set-parm=60

and resolution with ;

v4l2-ctl -d 1 --set-fmt-video=width=640,height=480

but when I try to ;

camcapture = cv2.VideoCapture(1) 
_,f = camcapture.read() 
cv2.imwrite(filename, f)

capture is 60fps BUT resolution is 320x240. It's obvious that cv2.VideoCapture changes the resolution. Ok so it doesn't care about v4l2-ctl written settings and overrides it's own. So I try ;

camcapture.set(3,640)
camcapture.set(4,480)

image is 640x480 as expected but frame rate decreases to 30fps. This time it overrides the fps value.Eventhough the camera supports it, I can not get it working at 640x480@60fps.

Any idea preventing cv2.VideoCapture overriding v4l2-ctl written settings ?

2
correct me if i am wrong, 640*480*3*60/1000000 = 55 MB/s throughput is what you need, but theoretical usb 2.0 limit is 60 MB - its uncommon to achieve that rate. so that specs saying that 640x480 @ 60 fps might imply grayscale output.baci

2 Answers

2
votes

OpenCV automatically selects the first available capture backend (see here). It can be that it is not using V4L2 automatically.

Also set both -D WITH_V4L=ON and -D WITH_LIBV4L=ON when building.

In order to set the pixel format to be used set the CAP_PROP_FOURCC property of the capture:

  capture = cv2.VideoCapture(self.cam_id, cv2.CAP_V4L2)
  capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
  width = 1920
  height = 1080
  capture.set(cv2.CAP_PROP_FRAME_WIDTH, width)
  capture.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
1
votes

Why don't you try to explicitly ask for the wanted framerate:

camcapture.set(cv2.cv.CV_CAP_PROP_FPS,60)

or if you prefer integer obfuscation:

camcapture.set(5,60)

So the camera will (perhaps) tell you something like:

HIGHGUI ERROR: V4L: Property <unknown property string>(5) not supported by device

PS: though changing 3 per cv2.cv.CV_CAP_PROP_FRAME_WIDTH, could help reading your code...