From 63b338751fffc6936b12e842a35f2cec86010407 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Sun, 17 Mar 2024 18:12:45 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=93=9D=20typing=20improvement=20f?= =?UTF-8?q?or=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)