Skip to content

Commit

Permalink
Merge pull request #482 from abhishek7kalra/linezonetrigger
Browse files Browse the repository at this point in the history
Linezone.trigger returns bool nparray
  • Loading branch information
SkalskiP committed Oct 18, 2023
2 parents a7449ba + fe8a826 commit 034c2bd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions supervision/detection/line_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ def __init__(self, start: Point, end: Point):
self.in_count: int = 0
self.out_count: int = 0

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.
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:
crossed = np.full(len(detections), False)

for i, (xyxy, _, confidence, class_id, tracker_id) in enumerate(detections):
# handle detections with no tracker_id
if tracker_id is None:
continue
Expand Down Expand Up @@ -67,8 +72,13 @@ def trigger(self, detections: Detections):
self.tracker_state[tracker_id] = tracker_state
if tracker_state:
self.in_count += 1
crossed[i] = True

else:
self.out_count += 1
crossed[i] = True

return crossed


class LineZoneAnnotator:
Expand Down

0 comments on commit 034c2bd

Please sign in to comment.