Pixel format of incoming image is unsupported by OpenCV

I am trying to get a video stream from a camera on my RPI 4. When I try to run this simple video capture script as a test to stream from /dev/video0, I get the following error:

import cv2
print("starting")
cap = cv2.VideoCapture(0)
if cap.isOpened():
    print("streaming!")

Error:

VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV

When running v4l2-ctl --device /dev/video0 --list-formats-ext, I get this output:
image

Although I am not sure how this can be used.
I don’t know where to begin fixing this problem. Any help would be appreciated!

congrats, you found a place where OpenCV is “incomplete”.

Is there any way to force my camera to use a supported pixel format?

there is, probably.

I’ve heard of v4l-ctl or v4l2-ctl, a command line utility. see if you can set the device’s pixel format using that.

try getting CAP_PROP_FORMAT and see if that’s an interesting value.

you could try setting CAP_PROP_FOURCC of the cv::VideoCapture instance. sometimes that can be a pixel format instead of a codec.

related: