Skip to content

Commit e5c4d8e

Browse files
committed
docs(example): πŸ“ Update tracking example with new annotators
Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
1 parent 52ef3fa commit e5c4d8e

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

β€Žexamples/tracking/script.pyβ€Ž

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def process_video(
1616
model = YOLO(source_weights_path)
1717

1818
tracker = sv.ByteTrack()
19-
box_annotator = sv.BoxAnnotator()
19+
box_annotator = sv.BoxLineAnnotator()
20+
label_annotator = sv.LabelAnnotator(classes=model.names)
2021
frame_generator = sv.get_video_frames_generator(source_path=source_video_path)
2122
video_info = sv.VideoInfo.from_video_path(video_path=source_video_path)
2223

@@ -28,16 +29,13 @@ def process_video(
2829
detections = sv.Detections.from_ultralytics(results)
2930
detections = tracker.update_with_detections(detections)
3031

31-
labels = [
32-
f"#{tracker_id} {model.model.names[class_id]}"
33-
for _, _, _, class_id, tracker_id in detections
34-
]
35-
3632
annotated_frame = box_annotator.annotate(
37-
scene=frame.copy(), detections=detections, labels=labels
38-
)
39-
40-
sink.write_frame(frame=annotated_frame)
33+
scene=frame.copy(), detections=detections)
34+
35+
annotated_labeled_frame = label_annotator.annotate(
36+
scene=annotated_frame, detections=detections)
37+
38+
sink.write_frame(frame=annotated_labeled_frame)
4139

4240

4341
if __name__ == "__main__":

β€Žsupervision/annotators/core.pyβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ class LabelAnnotator(BaseAnnotator):
229229
def __init__(
230230
self,
231231
color: Union[Color, ColorPalette] = ColorPalette.default(),
232-
thickness: int = 2,
233232
text_color: Color = Color.black(),
234233
text_scale: float = 0.5,
235234
text_thickness: int = 1,

0 commit comments

Comments
Β (0)