1634718277 Publish time 2022-7-8 15:32:36

suggestion: make camera_opencv.py compatible with rpiOs Bullseye

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).tobytes()

1750665706 Publish time 2025-6-23 16:05:46

Have you tried integrating more advanced image processing functions in cvt.elementDraw(img), like object detection or face recognition? I'm curious if Picamera2 has any performance impact when running in parallel with complex image processing threads?
Pages: [1]
View full version: suggestion: make camera_opencv.py compatible with rpiOs Bullseye