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):
VideoCapture
: cap = cv2.VideoCapture(0 , cv2.CAP_GSTREAMER)
, cap = cv2.VideoCapture(0 , cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH , ...)
, cap.set(cv2.CAP_PROP_FRAME_HEIGHT , ...)
VideoCapture
: cap.set("/dev/video0")
, cap.set("/dev/video1")
, ...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'))
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