Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracker_id contents are never None #1214

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions supervision/detection/line_zone.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Dict, Iterable, Optional, Tuple

import cv2
Expand All @@ -7,6 +8,7 @@
from supervision.draw.color import Color
from supervision.draw.utils import draw_text
from supervision.geometry.core import Point, Position, Vector
from supervision.utils.internal import SupervisionWarnings


class LineZone:
Expand Down Expand Up @@ -140,6 +142,15 @@ def trigger(self, detections: Detections) -> Tuple[np.ndarray, np.ndarray]:
if len(detections) == 0:
return crossed_in, crossed_out

if detections.tracker_id is None:
warnings.warn(
"Line zone counting skipped. LineZone requires tracker_id. Refer to "
"https://supervision.roboflow.com/latest/trackers for more "
"information.",
category=SupervisionWarnings,
)
return crossed_in, crossed_out

all_anchors = np.array(
[
detections.get_anchors_coordinates(anchor)
Expand All @@ -148,9 +159,6 @@ def trigger(self, detections: Detections) -> Tuple[np.ndarray, np.ndarray]:
)

for i, tracker_id in enumerate(detections.tracker_id):
if tracker_id is None:
continue

box_anchors = [Point(x=x, y=y) for x, y in all_anchors[:, i, :]]

in_limits = all(
Expand Down
10 changes: 6 additions & 4 deletions supervision/detection/tools/smoother.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import warnings
from collections import defaultdict, deque
from copy import deepcopy
from typing import Optional

import numpy as np

from supervision.detection.core import Detections
from supervision.utils.internal import SupervisionWarnings


class DetectionsSmoother:
Expand Down Expand Up @@ -70,16 +72,16 @@ def update_with_detections(self, detections: Detections) -> Detections:
"""

if detections.tracker_id is None:
print(
warnings.warn(
"Smoothing skipped. DetectionsSmoother requires tracker_id. Refer to "
"https://supervision.roboflow.com/latest/trackers for more information."
"https://supervision.roboflow.com/latest/trackers for more "
"information.",
category=SupervisionWarnings,
)
return detections

for detection_idx in range(len(detections)):
tracker_id = detections.tracker_id[detection_idx]
if tracker_id is None:
continue

self.tracks[tracker_id].append(detections[detection_idx])

Expand Down