OpenCV capturing image with black side bars

I had this exact issue with a Logitech wide angle in windows camera and I was wondering about a driver problem.

So I solved it using the DirectShow driver instead of the native driver using this:

cv2.VideoCapture(cv2.CAP_DSHOW)

If you have more than one camera add the index to that value like this

cv2.VideoCapture(cv2.CAP_DSHOW + camera_index)

It will accept the desired resolution by applying the right aspect ratio without having the sidebars.


The Answer of @luismesas is completely right and worked for me.

But for people being as unskilled as I am you need to save the capture returned by cv2.VideoCapture. It is not a Parameter you can set like cv2.VideoCapture(cv2.CAP_DSHOW), it is a method.

camera_index = 0
cap = cv2.VideoCapture(camera_index, cv2.CAP_DSHOW)
ret, frame = cap.read()

Confirmed on Webcam device HD PRO WEBCAM C920.


I had the same issue too, but only on Windows 10, OpenCV 3.4 and Python 3.7. I get the full resolution without the black side bars on a Mac OS.

I used PyGame to capture the webcam input and got the full resolution of 1920x1080 on Windows.

Tags:

Python

Opencv