From 79ae447e005e486f660570567ed94adbcf892635 Mon Sep 17 00:00:00 2001 From: WillB97 Date: Sat, 7 Dec 2024 10:38:12 +0000 Subject: [PATCH] Attempt to fix typing --- april_vision/utils.py | 5 +++-- april_vision/vision.py | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/april_vision/utils.py b/april_vision/utils.py index bec9fa1..6999e9e 100644 --- a/april_vision/utils.py +++ b/april_vision/utils.py @@ -30,7 +30,8 @@ def from_colour_frame( if colourspace is not None: grey_frame = cv2.cvtColor(colour_frame, colourspace) else: - grey_frame = colour_frame.copy() + # Mypy doesn't understand that Mat is a numpy array + grey_frame = colour_frame.copy() # type: ignore[assignment] return cls( grey_frame=grey_frame, @@ -62,7 +63,7 @@ def annotate_text( cv2.putText( frame_type, text, - np.array(location, dtype=np.int32), + location, cv2.FONT_HERSHEY_DUPLEX, text_scale, color=text_colour, # in BGR diff --git a/april_vision/vision.py b/april_vision/vision.py index 93d4b96..337b5bb 100644 --- a/april_vision/vision.py +++ b/april_vision/vision.py @@ -9,7 +9,7 @@ from pyapriltags import Detector from .frame_sources import FrameSource -from .marker import Marker +from .marker import Marker, PixelCoordinates from .utils import Frame, normalise_marker_text LOGGER = logging.getLogger(__name__) @@ -122,7 +122,7 @@ def _annotate( for frame_type in frame: cv2.polylines( frame_type, - [integer_corners], + integer_corners.tolist(), isClosed=True, color=(0, 255, 0), # Green (BGR) thickness=line_thickness, @@ -148,7 +148,7 @@ def _annotate( cv2.polylines( frame_type, - [origin_square], + origin_square.tolist(), isClosed=True, color=(0, 0, 255), # red thickness=line_thickness, @@ -157,9 +157,10 @@ def _annotate( marker_text_scale = text_scale * normalise_marker_text(marker) # Approximately center the text - text_origin = np.array(marker.pixel_centre, dtype=np.int32) - text_origin += np.array( - [-40 * marker_text_scale, 10 * marker_text_scale], dtype=np.int32) + text_origin = PixelCoordinates( + marker.pixel_centre.x - 40 * marker_text_scale, + marker.pixel_centre.y + 10 * marker_text_scale, + ) cv2.putText( frame_type,