y33t
y33t

Reputation: 679

how does cv2.VideoCapture() changes capture resolution?

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 ?

Upvotes: 3

Views: 32247

Answers (2)

zardosht
zardosht

Reputation: 3571

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)

Upvotes: 6

Alexandre Mazel
Alexandre Mazel

Reputation: 2558

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...

Upvotes: 2

Related Questions