-
Search before asking
QuestionI have been using the traffic_analysis example, but when trying to implement a separate counter for each class (car, bus, van, truck), I realized that it wouldn't be the same in other projects, mainly because the tracker_id seems to unify everything into one class. How could I implement this? AdditionalNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap. |
Beta Was this translation helpful? Give feedback.
-
Hi, @hugoles 👋🏻 Let me convert this issue into discussion and move it into the Q&A section. |
Beta Was this translation helpful? Give feedback.
-
Currently, This will only work well if the categories provided by your model are stable. import supervision as sv
from ultralytics import YOLO
# indexes of coco classes related to car, bus, truck
CLASS_IDS = [2, 5, 7]
SOURCE_PATH = ...
START = sv.Point(...)
END = sv.Point(...)
line_zones = {
class_id: sv.LineZone(start=START, end=END)
for class_id
in CLASS_IDS
}
frame_generator = sv.get_video_frames_generator(source_path='source.mp4')
for frame in frame_generator:
results = self.model(frame)[0]
detections = sv.Detections.from_ultralytics(results)
detections = self.tracker.update_with_detections(detections)
for class_id in CLASS_IDS:
class_detections = detections[detections.class_id == class_id]
line_zones[CLASS_IDS].trigger(class_detections) |
Beta Was this translation helpful? Give feedback.
@SkalskiP I really appreciate your help, even though I may not be using this code directly. It has helped me gain a better understanding of the code. Here's what I've accomplished so far: #562 (comment)