|
Hi
I use a PiCar Adeept_AWR.
I created a Sd card with RPI_os bullseye
The camera is declared non-legacy and therefore the camera_opencv.py program is incompatible with this configuration and must be modified using the new picamera2 library.
1 - install picamera2
https://github.com/raspberrypi/picamera2
2 - check libcamera installation
in a terminal enter "libcamera-hello"
3 - edit camera_opencv.py
add in header (I have it, put under import cv2)
from picamera2 import Picamera2
4 - At the end of the file modify the Camera class method
@staticmethod
def frames():
- @staticmethod
- def frames():
- # camera = cv2.VideoCapture(Camera.video_source) #,cv2.CAP_V4L2)
- camera = Picamera2(Camera.video_source)
- camera.configure(camera.create_preview_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
- camera.start()
- # if not camera.isOpened():
- # raise RuntimeError('Could not start camera.')
- cvt = CVThread()
- cvt.start()
- while True:
- # read current frame
- # _, img = camera.read()
- img = camera.capture_array()
- if Camera.modeSelect == 'none':
- switch.switch(1,0)
- cvt.pause()
- else:
- if cvt.CVThreading:
- pass
- else:
- cvt.mode(Camera.modeSelect, img)
- cvt.resume()
- try:
- img = cvt.elementDraw(img)
- except:
- pass
-
- # encode as a jpeg image and return it
- yield cv2.imencode('.jpg', img)[1].tobytes()
Copy the Code |
|