Workaround for OpenCV on Raspberry PI OS 11 'Bullseye'

I faced the problem that I want to use OpenCV on a RP 4B with 64 bit Raspberry Pi OS 11 ‘Bullseye’. The commands from the OpenCV library don’t work right with the new libcamera-based stack. Is there a proper workaround to run programs including OpenCV-commands with the new libcamera stack?

I read something about using a gstreamer pipeline… has anyone experience how it functions/can explain how to code it, maybe with example?

Thanks in advance


I’m not entirely sure how to do this from Python, but you can find out the gstreamer source we use in Edge Impulse for Linux via:

edge-impulse-linux --verbose

This’ll give you f.e. (Logitech C920 on bullseye):

gst-launch-1.0 uvch264src device=/dev/video0 ! video/x-raw,width=640,height=480 ! videoconvert ! jpegenc ! multifilesink location=test%05d.jpg

Reading through f.e. this article you should be able to replace everything after videoconvert ! with appsink and use that from Python:

camera = cv2.VideoCapture('uvch264src device=/dev/video0 ! video/x-raw,width=640,height=480 ! videoconvert ! appsink', cv2.CAP_GSTREAMER)

Maybe this works ^ ?

If so, please let me know and will see what we can do to hack something like this into the Python examples.