All image pixel values become 205 after setting CAP_PROP_FRAME_WIDTH and CAP_PROP_FRAME_HEIGHT in OpenCV using webcam

asked 2018-12-10 01:29:06 -0600

I use a webcam with default resolution of 640x480, the environment is OpenCV 4.0, visual studio 17 and win10. If I read directly from webcam everything is fine, but after I set CAP_PROP_FRAME_WIDTH and CAP_PROP_FRAME_HEIGHT, I can still get image from webcam but all pixel values become (205,205,205). The code is simple:

VideoCapture cap(0); 
cap.set(CAP_PROP_FRAME_WIDTH, 320); 
cap.set(CAP_PROP_FRAME_HEIGHT, 240); 
Mat img; 
cap.read(img);

What might cause the problem? Thank you!

edit retag flag offensive close merge delete

Comments

maybe try with :

VideoCapture cap(0+CAP_DSHOW);

(try to use the directshow backend instead of the default MSMF one)

berak gravatar imageberak ( 2018-12-11 00:35:10 -0600 )edit