diff --git a/robot/vision.py b/robot/vision.py index 9411796..8882d30 100644 --- a/robot/vision.py +++ b/robot/vision.py @@ -16,14 +16,7 @@ import cv2 import numpy as np -import picamera - -try: - import picamera.array - # seperate import of picamera.array required: - # -except ImportError: - pass # Mock RPI doesn't have picamera.array as a separate import +import picamera2 import robot.apriltags3 as AT @@ -164,7 +157,8 @@ class RoboConPiCamera(Camera): the robocon classes""" def __init__(self, start_res=(1296, 736), focal_lengths=None): - self._pi_camera = picamera.PiCamera(resolution=start_res) + self._pi_camera = picamera2.PiCamera2(resolution=start_res) + self._pi_camera.start() self.focal_lengths = (PI_CAMERA_FOCAL_LENGTHS if focal_lengths is None else focal_lengths) @@ -187,11 +181,9 @@ def res(self, new_res: tuple): def capture(self): # TODO Make this return the YUV capture - with picamera.array.PiRGBArray(self._pi_camera) as stream: - self._pi_camera.capture(stream, format="bgr", use_video_port=True) - capture_time = datetime.now() - colour_frame = stream.array - grey_frame = cv2.cvtColor(stream.array, cv2.COLOR_BGR2GRAY) + capture_time = datetime.now() + colour_frame = picam2.capture_array(): + grey_frame = cv2.cvtColor(stream.array, cv2.COLOR_BGR2GRAY) return Capture(grey_frame=grey_frame, colour_frame=colour_frame,