View: 754|Reply: 0

suggestion: make camera_opencv.py compatible with rpiOs Bullseye

[Copy link]

2

Threads

4

Posts

24

Credits

Newbie

Rank: 1

Credits
24
Post time 2022-7-8 15:32:36 | Show all posts |Read mode
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():


  1.     @staticmethod
  2.     def frames():
  3. #        camera = cv2.VideoCapture(Camera.video_source) #,cv2.CAP_V4L2)
  4.         camera = Picamera2(Camera.video_source)
  5.         camera.configure(camera.create_preview_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
  6.         camera.start()
  7. #        if not camera.isOpened():
  8. #            raise RuntimeError('Could not start camera.')

  9.         cvt = CVThread()
  10.         cvt.start()

  11.         while True:
  12.             # read current frame
  13. #            _, img = camera.read()
  14.             img = camera.capture_array()

  15.             if Camera.modeSelect == 'none':
  16.                 switch.switch(1,0)
  17.                 cvt.pause()
  18.             else:
  19.                 if cvt.CVThreading:
  20.                     pass
  21.                 else:
  22.                     cvt.mode(Camera.modeSelect, img)
  23.                     cvt.resume()
  24.                 try:
  25.                     img = cvt.elementDraw(img)
  26.                 except:
  27.                     pass
  28.             


  29.             # encode as a jpeg image and return it
  30.             yield cv2.imencode('.jpg', img)[1].tobytes()
Copy the Code
Reply

Use magic Report

You have to log in before you can reply Login | Sign Up

Points Rules