From e8810fe8a20ccb68744beac4c578fed383ccf92f Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Sun, 17 Mar 2024 14:41:47 +0300 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9E=20static=20type=20fix?= =?UTF-8?q?=20for=20color=20constants=20to=20sv.Color?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/draw/color.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/supervision/draw/color.py b/supervision/draw/color.py index 635ef47f..149908d8 100644 --- a/supervision/draw/color.py +++ b/supervision/draw/color.py @@ -176,31 +176,31 @@ class Color: return self.b, self.g, self.r @classproperty - def WHITE(cls): + def WHITE(cls) -> Color: return Color.from_hex("#FFFFFF") @classproperty - def BLACK(cls): + def BLACK(cls) -> Color: return Color.from_hex("#000000") @classproperty - def RED(cls): + def RED(cls) -> Color: return Color.from_hex("#FF0000") @classproperty - def GREEN(cls): + def GREEN(cls) -> Color: return Color.from_hex("#00FF00") @classproperty - def BLUE(cls): + def BLUE(cls) -> Color: return Color.from_hex("#0000FF") @classproperty - def YELLOW(cls): + def YELLOW(cls) -> Color: return Color.from_hex("#FFFF00") @classproperty - def ROBOFLOW(cls): + def ROBOFLOW(cls) -> Color: return Color.from_hex("#A351FB") @classmethod From 63b338751fffc6936b12e842a35f2cec86010407 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Sun, 17 Mar 2024 18:12:45 +0300 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=F0=9F=93=9D=20typing=20improvement?= =?UTF-8?q?=20for=20polygone=20zone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/detection/tools/polygon_zone.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/supervision/detection/tools/polygon_zone.py b/supervision/detection/tools/polygon_zone.py index d7f22835..00b746aa 100644 --- a/supervision/detection/tools/polygon_zone.py +++ b/supervision/detection/tools/polygon_zone.py @@ -3,6 +3,7 @@ from typing import Iterable, Optional, Tuple import cv2 import numpy as np +import numpy.typing as npt from supervision import Detections from supervision.detection.utils import clip_boxes, polygon_to_mask @@ -39,7 +40,7 @@ class PolygonZone: ) def __init__( self, - polygon: np.ndarray, + polygon: npt.NDArray[np.int64], frame_resolution_wh: Tuple[int, int], triggering_anchors: Iterable[Position] = (Position.BOTTOM_CENTER,), ): @@ -54,7 +55,7 @@ class PolygonZone: polygon=polygon, resolution_wh=(width + 1, height + 1) ) - def trigger(self, detections: Detections) -> np.ndarray: + def trigger(self, detections: Detections) -> npt.NDArray[np.bool_]: """ Determines if the detections are within the polygon zone. @@ -78,13 +79,13 @@ class PolygonZone: ] ) - is_in_zone = ( + is_in_zone: npt.NDArray[np.bool_] = ( self.mask[all_clipped_anchors[:, :, 1], all_clipped_anchors[:, :, 0]] .transpose() .astype(bool) ) - is_in_zone = np.all(is_in_zone, axis=1) + is_in_zone: npt.NDArray[np.bool_] = np.all(is_in_zone, axis=1) self.current_count = int(np.sum(is_in_zone)) return is_in_zone.astype(bool)