From 560a35b75f9fe860162b546df8ebbe2b9cbf4580 Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Thu, 28 Sep 2023 21:46:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20test=20`LabelAnnotator`=20suppor?= =?UTF-8?q?ting=20more=20`Position`=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/annotators/core.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index cadddf5a..a1a79726 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -334,8 +334,32 @@ class LabelAnnotator: ) -> Tuple[int, int, int, int]: padded_text_wh = (text_wh[0] + 2 * text_padding, text_wh[1] + 2 * text_padding) x1, y1, x2, y2 = detection_xyxy + center_x = (x1 + x2) // 2 + center_y = (y1 + y2) // 2 + if position == Position.TOP_LEFT: return x1, y1 - padded_text_wh[1], x1 + padded_text_wh[0], y1 + elif position == Position.TOP_RIGHT: + return x2 - padded_text_wh[0], y1 - padded_text_wh[1], x2, y1 + elif position == Position.TOP_CENTER: + return ( + center_x - padded_text_wh[0] // 2, y1 - padded_text_wh[1], + center_x + padded_text_wh[0] // 2, y1 + ) + elif position == Position.CENTER: + return ( + center_x - padded_text_wh[0] // 2, center_y - padded_text_wh[1] // 2, + center_x + padded_text_wh[0] // 2, center_y + padded_text_wh[1] // 2 + ) + elif position == Position.BOTTOM_LEFT: + return x1, y2, x1 + padded_text_wh[0], y2 + padded_text_wh[1] + elif position == Position.BOTTOM_RIGHT: + return x2 - padded_text_wh[0], y2, x2, y2 + padded_text_wh[1] + elif position == Position.BOTTOM_CENTER: + return ( + center_x - padded_text_wh[0] // 2, y2, + center_x + padded_text_wh[0] // 2, y2 + padded_text_wh[1] + ) def annotate( self,