From 338c589032336ff51a93096182a5405d992f2598 Mon Sep 17 00:00:00 2001 From: abhishek7kalra Date: Sun, 15 Oct 2023 17:42:40 +0530 Subject: [PATCH 1/3] LineZone.trigger update to return info --- supervision/detection/line_counter.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/supervision/detection/line_counter.py b/supervision/detection/line_counter.py index ea97fcb8..db86e3f9 100644 --- a/supervision/detection/line_counter.py +++ b/supervision/detection/line_counter.py @@ -26,6 +26,7 @@ class LineZone: self.tracker_state: Dict[str, bool] = {} self.in_count: int = 0 self.out_count: int = 0 + self.crossed = [] def trigger(self, detections: Detections): """ @@ -33,9 +34,14 @@ class LineZone: Attributes: detections (Detections): The detections for which to update the counts. - + + Returns: + np.ndarray: A boolean array indicating + which detection has crossed the line on the either sides """ - for xyxy, _, confidence, class_id, tracker_id in detections: + self.crossed = [False] * len(detections) + + for i, (xyxy, _, confidence, class_id, tracker_id) in enumerate(detections): # handle detections with no tracker_id if tracker_id is None: continue @@ -67,8 +73,13 @@ class LineZone: self.tracker_state[tracker_id] = tracker_state if tracker_state: self.in_count += 1 + self.crossed[i] = True + else: self.out_count += 1 + self.crossed[i] = True + + return self.crossed class LineZoneAnnotator: From bf725ef0f72699079152d3630a5f27c6acf27311 Mon Sep 17 00:00:00 2001 From: abhishek7kalra Date: Sun, 15 Oct 2023 18:10:54 +0530 Subject: [PATCH 2/3] fix pre-commit --- supervision/detection/line_counter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/detection/line_counter.py b/supervision/detection/line_counter.py index db86e3f9..1c1fe770 100644 --- a/supervision/detection/line_counter.py +++ b/supervision/detection/line_counter.py @@ -34,7 +34,7 @@ class LineZone: Attributes: detections (Detections): The detections for which to update the counts. - + Returns: np.ndarray: A boolean array indicating which detection has crossed the line on the either sides From fe8a8260dcdf1181d28c0de4d748c3c557c08a90 Mon Sep 17 00:00:00 2001 From: abhishek7kalra Date: Sun, 15 Oct 2023 19:06:18 +0530 Subject: [PATCH 3/3] change return type from list to nparray --- supervision/detection/line_counter.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/supervision/detection/line_counter.py b/supervision/detection/line_counter.py index 1c1fe770..c668354e 100644 --- a/supervision/detection/line_counter.py +++ b/supervision/detection/line_counter.py @@ -26,9 +26,8 @@ class LineZone: self.tracker_state: Dict[str, bool] = {} self.in_count: int = 0 self.out_count: int = 0 - self.crossed = [] - def trigger(self, detections: Detections): + def trigger(self, detections: Detections) -> np.ndarray: """ Update the in_count and out_count for the detections that cross the line. @@ -39,7 +38,7 @@ class LineZone: np.ndarray: A boolean array indicating which detection has crossed the line on the either sides """ - self.crossed = [False] * len(detections) + crossed = np.full(len(detections), False) for i, (xyxy, _, confidence, class_id, tracker_id) in enumerate(detections): # handle detections with no tracker_id @@ -73,13 +72,13 @@ class LineZone: self.tracker_state[tracker_id] = tracker_state if tracker_state: self.in_count += 1 - self.crossed[i] = True + crossed[i] = True else: self.out_count += 1 - self.crossed[i] = True + crossed[i] = True - return self.crossed + return crossed class LineZoneAnnotator: