pythonopencvwebcam

Accessing full web cam resolution in opencv python


I have a new ThinkPad t14s laptop with a built in Chicony web cam, running manjaro linux. When running cheese I see that the resolution is a nice 2592x1944. However when capturing a frame in opencv python the resolution is only 640x480. Advice would be greatly appreciated. The things I've tried (from suggestions found online):

Unfortunately nothing works, the resolution I end up with is 640x480.

EDIT: This worked for me (thanks Maja):

import cv2

cap = cv2.VideoCapture("/dev/video0")
cap.set(cv2.CAP_PROP_FPS , 60.0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2592)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1944)
cap.set(cv2.CAP_PROP_FOURCC , cv2.VideoWriter.fourcc('M' , 'J' , 'P' , 'G'))

Solution

  • Make sure that the width/height you are setting are actually supported. I believe if they are not it will just fallback to default.

    You can check supported resolutions and frame rates by

    v4l2-ctl -d /dev/video0 --list-formats-ext

    Look at which codecs are supported for each of the resolutions as well and set it accordingly. This might help: Changing codec of webcam is not possible using OpenCV/Python