Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4741

Troubleshooting • Do I have to rewrite my opencv python code for bookworm?

$
0
0
I installed bookworm on a pi 4 8gb. Libcamera stuff works, so does PiCamera2. I am trying to get all of my opencv programs running. A simple camera snippet won't work.

Code:

import numpy as npimport cv2import timewinname='camera0'cap = cv2.VideoCapture(0)while(True):    # Capture frame-by-frame    ret, frame = cap.read()    if not ret:        break    # Display the resulting frame    cv2.imshow(winname,frame)    key = cv2.waitKey(20)    if key & 0xFF == ord('q'):        breakcap.release()cv2.destroyAllWindows()
the message was:

Code:

[ WARN:0@0.274] global ./modules/videoio/src/cap_gstreamer.cpp (2401) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Failed to allocate required memory.[ WARN:0@0.276] global ./modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline[ WARN:0@0.276] global ./modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been createdread framegot nada
I trieed

Code:

pip install opencv-contrib-python --break-system-packages
And the code still lead to errors. I uninstalled with pip.
I tried

Code:

sudo apt install python3-opencv
And the code still lead to errors. At this time I removed with

Code:

sudo apt remove python3-opencv
And now I can't import cv2. Genius. I read many posts at various places. It seems the solution is to rewrite code to use PiCamera2? Is this the answer? That will take some work that I wasn't expecting. Please share a guide on how to run stretch/bullseye python opencv code on pi bookworm without code changes.

Statistics: Posted by bluePiuser — Wed Jun 05, 2024 1:45 am



Viewing all articles
Browse latest Browse all 4741

Trending Articles