From c35a7714d2b217c76b60a9d9348ee7ba2e85efcd Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Thu, 28 Sep 2023 17:11:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Test=20of=20`BoxCornerAnnotator`?= =?UTF-8?q?=20alternative=20`annotate`=20method=20implementation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/annotators/core.py | 73 ++++++++-------------------------- 1 file changed, 17 insertions(+), 56 deletions(-) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index e373b367..46282847 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -290,62 +290,23 @@ class BoxCornerAnnotator(BaseAnnotator): color_map=self.color_map, ) color = resolve_color(color=self.color, idx=idx) - cv2.line( - scene, - (x1, y1), - (x1 + self.corner_length, y1), - color.as_bgr(), - thickness=self.thickness, - ) - cv2.line( - scene, - (x2 - self.corner_length, y1), - (x2, y1), - color.as_bgr(), - thickness=self.thickness, - ) - cv2.line( - scene, - (x1, y2), - (x1 + self.corner_length, y2), - color.as_bgr(), - thickness=self.thickness, - ) - cv2.line( - scene, - (x2 - self.corner_length, y2), - (x2, y2), - color.as_bgr(), - thickness=self.thickness, - ) - cv2.line( - scene, - (x1, y1), - (x1, y1 + self.corner_length), - color.as_bgr(), - thickness=self.thickness, - ) - cv2.line( - scene, - (x2, y1 + self.corner_length), - (x2, y1), - color.as_bgr(), - thickness=self.thickness, - ) - cv2.line( - scene, - (x1, y2 - self.corner_length), - (x1, y2), - color.as_bgr(), - thickness=self.thickness, - ) - cv2.line( - scene, - (x2, y2 - self.corner_length), - (x2, y2), - color.as_bgr(), - thickness=self.thickness, - ) + corners = [ + (x1, y1), (x2, y1), + (x1, y2), (x2, y2) + ] + + for x, y in corners: + x_end = x + self.corner_length if x == x1 else x - self.corner_length + cv2.line( + scene, (x, y), (x_end, y), + color.as_bgr(), thickness=self.thickness + ) + + y_end = y + self.corner_length if y == y1 else y - self.corner_length + cv2.line( + scene, (x, y), (x, y_end), + color.as_bgr(), thickness=self.thickness + ) return scene