Skip to content

Commit

Permalink
Fix typing of updated numpy and opencv
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed Dec 7, 2024
1 parent 4301fe2 commit dbd81b6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion april_vision/cli/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def main(args: argparse.Namespace) -> None:
width, height = frames[0].grey_frame.shape[::-1]

# Calculate the camera calibration
reproj_error, camera_matrix, dist_coeff, _rvec, _tvec = cv2.calibrateCamera(
# typehints are incorrect for this function, so we ignore them
reproj_error, camera_matrix, dist_coeff, _rvec, _tvec = cv2.calibrateCamera( # type: ignore[call-overload,unused-ignore]
objectPoints,
imagePoints,
(width, height),
Expand Down
6 changes: 3 additions & 3 deletions april_vision/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Deque, NamedTuple, Optional, Tuple, Union

import cv2
import numpy as np
from numpy.typing import NDArray

from .marker import Marker, PixelCoordinates
Expand All @@ -30,7 +29,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 until numpy 2.1
grey_frame = colour_frame.copy() # type: ignore[assignment,unused-ignore]

return cls(
grey_frame=grey_frame,
Expand Down Expand Up @@ -62,7 +62,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
Expand Down
13 changes: 8 additions & 5 deletions april_vision/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def _annotate(
for frame_type in frame:
cv2.polylines(
frame_type,
[integer_corners],
# mypy doesn't understand that Mat is a numpy array until numpy 2.1
[integer_corners], # type: ignore[assignment,unused-ignore]
isClosed=True,
color=(0, 255, 0), # Green (BGR)
thickness=line_thickness,
Expand All @@ -148,7 +149,8 @@ def _annotate(

cv2.polylines(
frame_type,
[origin_square],
# mypy doesn't understand that Mat is a numpy array until numpy 2.1
[origin_square], # type: ignore[assignment,unused-ignore]
isClosed=True,
color=(0, 0, 255), # red
thickness=line_thickness,
Expand All @@ -157,9 +159,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 = (
int(marker.pixel_centre.x - 40 * marker_text_scale),
int(marker.pixel_centre.y + 10 * marker_text_scale),
)

cv2.putText(
frame_type,
Expand Down

0 comments on commit dbd81b6

Please sign in to comment.