From db0d965e8df6014c2d058f8d4abc6ef2b0c9159d Mon Sep 17 00:00:00 2001 From: LinasKo Date: Thu, 26 Sep 2024 12:12:53 +0300 Subject: [PATCH] Fix: incorrect label rotation --- supervision/detection/line_zone.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/supervision/detection/line_zone.py b/supervision/detection/line_zone.py index a62437ec..e77d4057 100644 --- a/supervision/detection/line_zone.py +++ b/supervision/detection/line_zone.py @@ -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