# 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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
yolov8小型旋翼无人机检测,训练好的权重,可以直接使用,并附有数据集,数据集目录已经配置好,yolo格式(txt)的标签,划分好 train,val, test,并附有data.yaml文件,yolov5、yolov7、yolov8等算法可以直接进行训练模型, 数据集和检测结果参考: https://blog.csdn.net/zhiqingAI/article/details/124230743 https://blog.csdn.net/zhiqingAI/article/details/136952543 数据集配置目录结构data.yaml: nc: 1 drone pyqt界面可以 检测图片、视频和调用摄像头,有相应的选择项,教程详细,可直接使用;
资源推荐
资源详情
资源评论
收起资源包目录
yolov8小型旋翼无人机检测权重+数据集+详细教程+pyqt可视化GUI界面 (436个子文件)
events.out.tfevents.1711755392.USER-20231125JB.5856.0 371KB
results.csv 33KB
Dockerfile 821B
train_batch2.jpg 778KB
train_batch1.jpg 744KB
train_batch22142.jpg 719KB
train_batch22141.jpg 685KB
train_batch22140.jpg 684KB
train_batch0.jpg 669KB
val_batch2_pred.jpg 587KB
val_batch2_labels.jpg 577KB
bus.jpg 476KB
val_batch0_pred.jpg 440KB
val_batch0_labels.jpg 427KB
val_batch1_pred.jpg 334KB
val_batch1_labels.jpg 321KB
labels_correlogram.jpg 238KB
background.jpg 181KB
labels.jpg 155KB
2024_04_06_21_11_44.jpg 138KB
2024_04_06_21_11_13.jpg 138KB
bus.jpg 134KB
ski.jpg 131KB
exe_location.JPG 57KB
zidane.jpg 49KB
icon.jpg 36KB
setting.json 83B
fold.json 60B
ip.json 54B
README.md 13KB
README.md 11KB
【yolov3-YOLOv5-yolov7-yolov8环境配置-教程1】.md 10KB
【yolov3-YOLOv5-yolov7-yolov8环境配置-教程2】.md 5KB
README.md 3KB
README.md 2KB
yolov8-pyqt运行步骤(配置好环境后执行).md 2KB
dance.mp4 5.79MB
best.onnx 11.65MB
【yolov3-YOLOv5-yolov7-yolov8环境配置-教程1】.pdf 6.55MB
yolov8-pyqt运行步骤(配置好环境后执行).pdf 1.71MB
【yolov3-YOLOv5-yolov7-yolov8环境配置-教程2】.pdf 580KB
背景.png 2.39MB
SingleWin.png 986KB
Running.png 587KB
GUI_new.png 366KB
results.png 246KB
R_curve.png 91KB
F1_curve.png 90KB
confusion_matrix.png 90KB
confusion_matrix_normalized.png 85KB
icon-1.png 84KB
P_curve.png 83KB
PR_curve.png 81KB
运行.png 9KB
赞停.png 6KB
icon.png 5KB
表情.png 4KB
数据探索.png 4KB
ֹͣ.png 3KB
摄像头关.png 3KB
doctor.png 3KB
evil.png 3KB
摄像头开.png 3KB
实时视频流解析.png 2KB
button-on.png 2KB
暂停.png 2KB
打开.png 2KB
终止.png 1KB
button-off.png 1KB
Բ.png 1KB
笑脸.png 786B
正方形.png 718B
箭头_列表展开.png 668B
箭头_列表收起.png 645B
关闭.png 605B
还原.png 601B
下拉_白色.png 573B
最大化.png 406B
最小化.png 249B
yolov5s.pt 14.12MB
yolov8n.pt 6.23MB
yolov8n.pt 6.23MB
last.pt 5.97MB
best.pt 5.97MB
apprcc_rc.py 11.22MB
metrics.py 52KB
exporter.py 51KB
augment.py 51KB
win.py 47KB
datasets.py 45KB
plotting.py 43KB
tasks.py 38KB
model.py 37KB
__init__.py 36KB
general.py 36KB
trainer.py 34KB
ops.py 32KB
loss.py 32KB
utils.py 29KB
tiny_encoder.py 28KB
共 436 条
- 1
- 2
- 3
- 4
- 5
资源评论
stsdddd
- 粉丝: 2w+
- 资源: 729
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 重庆市首席信息官(CIO)协会 《软件及信息化工程造价规范V5.0》T/CQCIO 001-2019
- 联想Y471老A卡笔记本开机黑屏 需等待黑屏结束才能进入桌面,解决方法
- elasticsearch-7.14.0和ik分词器
- 利用MPI计算任意范围内的质数
- EnviroSkyandWeather v2.1.1(u2017.1.2)真实动态天气系统包
- React框架介绍及相关教程、案例.docx
- 基于Springboot和Vue教务评教系统(PC端+server端源码+数据库MySQL脚本+环境部署步骤讲解+运行步骤讲解)
- react-photo-view图片预览组件
- 雷赛控制C#使用包含定位、插补运动等
- 自存spss参考资料资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功