# Multi-Object Tracking with Ultralytics YOLO
<img width="1024" src="https://user-images.githubusercontent.com/26833433/243418637-1d6250fd-1515-4c10-a844-a32818ae6d46.png" alt="YOLOv8 trackers visualization">
Object tracking in the realm of video analytics is a critical task that not only identifies the location and class of objects within the frame but also maintains a unique ID for each detected object as the video progresses. The applications are limitless—ranging from surveillance and security to real-time sports analytics.
## Why Choose Ultralytics YOLO for Object Tracking?
The output from Ultralytics trackers is consistent with standard object detection but has the added value of object IDs. This makes it easy to track objects in video streams and perform subsequent analytics. Here's why you should consider using Ultralytics YOLO for your object tracking needs:
- **Efficiency:** Process video streams in real-time without compromising accuracy.
- **Flexibility:** Supports multiple tracking algorithms and configurations.
- **Ease of Use:** Simple Python API and CLI options for quick integration and deployment.
- **Customizability:** Easy to use with custom trained YOLO models, allowing integration into domain-specific applications.
**Video Tutorial:** [Object Detection and Tracking with Ultralytics YOLOv8](https://www.youtube.com/embed/hHyHmOtmEgs?si=VNZtXmm45Nb9s-N-).
## Features at a Glance
Ultralytics YOLO extends its object detection features to provide robust and versatile object tracking:
- **Real-Time Tracking:** Seamlessly track objects in high-frame-rate videos.
- **Multiple Tracker Support:** Choose from a variety of established tracking algorithms.
- **Customizable Tracker Configurations:** Tailor the tracking algorithm to meet specific requirements by adjusting various parameters.
## Available Trackers
Ultralytics YOLO supports the following tracking algorithms. They can be enabled by passing the relevant YAML configuration file such as `tracker=tracker_type.yaml`:
- [BoT-SORT](https://github.com/NirAharon/BoT-SORT) - Use `botsort.yaml` to enable this tracker.
- [ByteTrack](https://github.com/ifzhang/ByteTrack) - Use `bytetrack.yaml` to enable this tracker.
The default tracker is BoT-SORT.
## Tracking
To run the tracker on video streams, use a trained Detect, Segment or Pose model such as YOLOv8n, YOLOv8n-seg and YOLOv8n-pose.
#### Python
```python
from ultralytics import YOLO
# Load an official or custom model
model = YOLO("yolov8n.pt") # Load an official Detect model
model = YOLO("yolov8n-seg.pt") # Load an official Segment model
model = YOLO("yolov8n-pose.pt") # Load an official Pose model
model = YOLO("path/to/best.pt") # Load a custom trained model
# Perform tracking with the model
results = model.track(
source="https://youtu.be/LNwODJXcvt4", show=True
) # Tracking with default tracker
results = model.track(
source="https://youtu.be/LNwODJXcvt4", show=True, tracker="bytetrack.yaml"
) # Tracking with ByteTrack tracker
```
#### CLI
```bash
# Perform tracking with various models using the command line interface
yolo track model=yolov8n.pt source="https://youtu.be/LNwODJXcvt4" # Official Detect model
yolo track model=yolov8n-seg.pt source="https://youtu.be/LNwODJXcvt4" # Official Segment model
yolo track model=yolov8n-pose.pt source="https://youtu.be/LNwODJXcvt4" # Official Pose model
yolo track model=path/to/best.pt source="https://youtu.be/LNwODJXcvt4" # Custom trained model
# Track using ByteTrack tracker
yolo track model=path/to/best.pt tracker="bytetrack.yaml"
```
As can be seen in the above usage, tracking is available for all Detect, Segment and Pose models run on videos or streaming sources.
## Configuration
### Tracking Arguments
Tracking configuration shares properties with Predict mode, such as `conf`, `iou`, and `show`. For further configurations, refer to the [Predict](https://docs.ultralytics.com/modes/predict/) model page.
#### Python
```python
from ultralytics import YOLO
# Configure the tracking parameters and run the tracker
model = YOLO("yolov8n.pt")
results = model.track(
source="https://youtu.be/LNwODJXcvt4", conf=0.3, iou=0.5, show=True
)
```
#### CLI
```bash
# Configure tracking parameters and run the tracker using the command line interface
yolo track model=yolov8n.pt source="https://youtu.be/LNwODJXcvt4" conf=0.3, iou=0.5 show
```
### Tracker Selection
Ultralytics also allows you to use a modified tracker configuration file. To do this, simply make a copy of a tracker config file (for example, `custom_tracker.yaml`) from [ultralytics/cfg/trackers](https://github.com/ultralytics/ultralytics/tree/main/ultralytics/cfg/trackers) and modify any configurations (except the `tracker_type`) as per your needs.
#### Python
```python
from ultralytics import YOLO
# Load the model and run the tracker with a custom configuration file
model = YOLO("yolov8n.pt")
results = model.track(
source="https://youtu.be/LNwODJXcvt4", tracker="custom_tracker.yaml"
)
```
#### CLI
```bash
# Load the model and run the tracker with a custom configuration file using the command line interface
yolo track model=yolov8n.pt source="https://youtu.be/LNwODJXcvt4" tracker='custom_tracker.yaml'
```
For a comprehensive list of tracking arguments, refer to the [ultralytics/cfg/trackers](https://github.com/ultralytics/ultralytics/tree/main/ultralytics/cfg/trackers) page.
## Python Examples
### Persisting Tracks Loop
Here is a Python script using OpenCV (`cv2`) and YOLOv8 to run object tracking on video frames. This script still assumes you have already installed the necessary packages (`opencv-python` and `ultralytics`). The `persist=True` argument tells the tracker than the current image or frame is the next in a sequence and to expect tracks from the previous image in the current image.
#### Python
```python
import cv2
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO("yolov8n.pt")
# Open the video file
video_path = "path/to/video.mp4"
cap = cv2.VideoCapture(video_path)
# Loop through the video frames
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 tracking on the frame, persisting tracks between frames
results = model.track(frame, persist=True)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Tracking", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()
```
Please note the change from `model(frame)` to `model.track(frame)`, which enables object tracking instead of simple detection. This modified script will run the tracker on each frame of the video, visualize the results, and display them in a window. The loop can be exited by pressing 'q'.
### Plotting Tracks Over Time
Visualizing object tracks over consecutive frames can provide valuable insights into the movement patterns and behavior of detected objects within a video. With Ultralytics YOLOv8, plotting these tracks is a seamless and efficient process.
In the following example, we demonstrate how to utilize YOLOv8's tracking capabilities to plot the movement of detected objects across multiple video frames. This script involves opening a video file, reading it frame by frame, and utilizing the YOLO model to identify and track various objects. By retaining the center points of the detected bounding boxes and connecting them, we can draw lines that represent the paths followed by the tracked objects.
#### Python
```python
from collections import defaultdict
import cv2
import numpy as np
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO("y
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1、YOLOv8水下垃圾检测,包含训练好的水下垃圾检测权重,以及PR曲线,loss曲线等等; 2、包含VOC水下垃圾检测数据集,几千张使用lableimg标注软件,标注好的真实场景的高质量图片数据,图片格式为jpg,标签有两种,分别为VOC格式和yolo格式,分别保存在两个文件夹中,包含许多不同类型的海洋垃圾的图像;数据场景丰富;类别为metal、wood、platstic、rubber、cloth等多个类别目标; 3、数据集和检测结果参考:https://blog.csdn.net/zhiqingAI/article/details/12423074 4、pyqt界面
资源推荐
资源详情
资源评论
收起资源包目录
YOLOv8水下垃圾检测+训练好的模型+标注好的数据集+pyqt可视化界面 (2000个子文件)
README.md 13KB
README.md 11KB
README.md 3KB
README.md 2KB
【yolov3-YOLOv5-yolov7-yolov8环境配置-教程1】.pdf 6.55MB
yolov8-pyqt运行步骤(配置好环境后执行).pdf 1.71MB
【yolov3-YOLOv5-yolov7-yolov8环境配置-教程2】.pdf 580KB
apprcc_rc.py 11.22MB
win.py 47KB
obj1602_frame0000085.txt 930B
obj1602_frame0000002.txt 836B
obj1602_frame0000083.txt 787B
obj0332_frame0000017.txt 618B
obj0749_frame0000132.txt 545B
obj0749_frame0000142.txt 536B
obj1050_frame0000150.txt 526B
obj0332_frame0000069.txt 522B
obj1050_frame0000079.txt 519B
obj1618_frame0000103.txt 519B
obj0305_frame0000013.txt 514B
obj1050_frame0000113.txt 510B
obj0332_frame0000025.txt 508B
obj1602_frame0000006.txt 505B
obj0749_frame0000125.txt 504B
obj0332_frame0000068.txt 500B
obj1618_frame0000096.txt 497B
obj0332_frame0000024.txt 496B
obj1050_frame0000009.txt 495B
obj0749_frame0000135.txt 495B
obj0305_frame0000029.txt 487B
obj1603_frame0000039.txt 481B
obj0332_frame0000019.txt 480B
obj0332_frame0000027.txt 478B
obj1618_frame0000085.txt 478B
obj1051_frame0000001.txt 477B
obj1616_frame0000005.txt 470B
obj1616_frame0000017.txt 468B
obj1616_frame0000110.txt 465B
obj0305_frame0000048.txt 464B
obj1617_frame0000061.txt 456B
obj0309_frame0000137.txt 456B
obj0212_frame0000041.txt 453B
obj1617_frame0000019.txt 451B
obj1617_frame0000071.txt 451B
obj0309_frame0000116.txt 451B
obj1617_frame0000214.txt 450B
obj1617_frame0000126.txt 450B
obj0309_frame0000080.txt 448B
obj1617_frame0000204.txt 448B
obj1617_frame0000112.txt 447B
obj1617_frame0000011.txt 446B
obj1617_frame0000228.txt 445B
obj1617_frame0000114.txt 445B
obj0309_frame0000133.txt 445B
obj1616_frame0000013.txt 443B
obj1618_frame0000202.txt 441B
obj0332_frame0000063.txt 438B
obj1617_frame0000210.txt 438B
obj1617_frame0000194.txt 438B
obj1616_frame0000021.txt 437B
obj1617_frame0000198.txt 436B
obj0309_frame0000097.txt 435B
obj0305_frame0000007.txt 434B
obj1617_frame0000188.txt 431B
obj0212_frame0000047.txt 431B
obj1617_frame0000124.txt 428B
obj1617_frame0000007.txt 427B
obj1617_frame0000067.txt 426B
obj1617_frame0000049.txt 425B
obj1617_frame0000122.txt 423B
obj0309_frame0000113.txt 423B
obj0305_frame0000055.txt 420B
obj0301_frame0000060.txt 419B
obj1617_frame0000190.txt 417B
obj1617_frame0000186.txt 416B
obj1617_frame0000053.txt 416B
obj1616_frame0000112.txt 416B
obj1617_frame0000017.txt 415B
obj0309_frame0000121.txt 414B
obj1617_frame0000192.txt 414B
obj1616_frame0000003.txt 411B
obj0309_frame0000102.txt 411B
obj1617_frame0000078.txt 410B
obj1617_frame0000082.txt 410B
obj1663_frame0000570.txt 409B
obj0309_frame0000128.txt 408B
obj0000_frame0000008.txt 406B
obj0002_frame0000017.txt 406B
obj0000_frame0000016.txt 406B
obj0309_frame0000129.txt 406B
obj1616_frame0000041.txt 405B
obj0309_frame0000105.txt 405B
obj1617_frame0000138.txt 405B
obj0309_frame0000039.txt 403B
obj0310_frame0000032.txt 403B
obj1616_frame0000114.txt 401B
obj1618_frame0000146.txt 400B
obj0084_frame0000040.txt 398B
obj1617_frame0000200.txt 395B
obj0707_frame0000016.txt 395B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
stsdddd
- 粉丝: 2w+
- 资源: 686
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功