最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Accessing full web cam resolution in opencv python - Stack Overflow

programmeradmin2浏览0评论

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):

  • adding extra argument to VideoCapture: cap = cv2.VideoCapture(0 , cv2.CAP_GSTREAMER) , cap = cv2.VideoCapture(0 , cv2.CAP_DSHOW)
  • changing the resolution, even tried to change the resolution to some ridiculously high value (10000) as was suggested somewhere: cap.set(cv2.CAP_PROP_FRAME_WIDTH , ...), cap.set(cv2.CAP_PROP_FRAME_HEIGHT , ...)
  • supplying the device file path to 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'))

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):

  • adding extra argument to VideoCapture: cap = cv2.VideoCapture(0 , cv2.CAP_GSTREAMER) , cap = cv2.VideoCapture(0 , cv2.CAP_DSHOW)
  • changing the resolution, even tried to change the resolution to some ridiculously high value (10000) as was suggested somewhere: cap.set(cv2.CAP_PROP_FRAME_WIDTH , ...), cap.set(cv2.CAP_PROP_FRAME_HEIGHT , ...)
  • supplying the device file path to 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'))
Share Improve this question edited Feb 17 at 10:46 kacper asked Feb 17 at 10:03 kacperkacper 774 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

发布评论

评论列表(0)

  1. 暂无评论