You can use the Python interface to track objects using the YOLO model.
```python
```python
from ultralytics import YOLO
from ultralytics import YOLO
@ -17,17 +19,68 @@ model.track(
source="video/streams",
source="video/streams",
stream=True,
stream=True,
tracker="botsort.yaml", # or 'bytetrack.yaml'
tracker="botsort.yaml", # or 'bytetrack.yaml'
...,
show=True,
)
)
```
```
cli:
You can get the IDs of the tracked objects using the following code:
```python
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
for result in model.track(source="video.mp4"):
print(
result.boxes.id.cpu().numpy().astype(int)
) # this will print the IDs of the tracked objects in the frame
```
If you want to use the tracker with a folder of images or when you loop on the video frames, you should use the `persist` parameter to tell the model that these frames are related to each other so the IDs will be fixed for the same objects. Otherwise, the IDs will be different in each frame because in each loop, the model creates a new object for tracking, but the `persist` parameter makes it use the same object for tracking.