Fix: incorrect label rotation

This commit is contained in:
LinasKo 2024-09-26 12:12:53 +03:00
parent 156dbd5046
commit db0d965e8d
1 changed files with 4 additions and 4 deletions

View File

@ -493,10 +493,6 @@ class LineZoneAnnotator:
)
assert label_image.shape[0] == label_image.shape[1]
# Make sure text is displayed upright
if line_zone.vector.start.x > line_zone.vector.end.x:
label_image = cv2.flip(label_image, flipCode=-1)
text_width, text_height = cv2.getTextSize(
text, cv2.FONT_HERSHEY_SIMPLEX, self.text_scale, self.text_thickness
)[0]
@ -574,6 +570,10 @@ class LineZoneAnnotator:
)
annotation = np.dstack((annotation, annotation_alpha))
# Make sure text is displayed upright
if 90 < line_angle_degrees % 360 < 270:
annotation = cv2.flip(annotation, flipCode=-1).astype(np.uint8)
rotation_angle = -line_angle_degrees
rotation_matrix = cv2.getRotationMatrix2D(
annotation_center.as_xy_float_tuple(), rotation_angle, scale=1