# 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俯视视角下舰船目标检测+训练好的舰船目标检测模型+舰船目标检测数据集;YOLOv8俯视视角下舰船目标检测+训练好的舰船目标检测模型+舰船目标检测数据集;YOLOv8俯视视角下舰船目标检测+训练好的舰船目标检测模型+舰船目标检测数据集;遥感舰船检测,无人机视角舰船检测 2、并包含舰船目标检测数据集,标签格式txt,配置好环境后可以直接使用 3、数据集和检测结果参考:https://blog.csdn.net/zhiqingAI/article/details/124230743 https://blog.csdn.net/zhiqingAI/article/details/135893083 4、采用pytrch框架,python代码 收起
资源推荐
资源详情
资源评论
收起资源包目录
YOLOv8俯视视角下舰船目标检测+训练好的舰船目标检测模型+舰船目标检测数据集+pyqt可视化界面 (2000个子文件)
train.cache 257KB
val.cache 42KB
Dockerfile 821B
155.jpg 12.61MB
187.jpg 11.12MB
862.jpg 11.03MB
300.jpg 10.96MB
336.jpg 10.7MB
252.jpg 10.68MB
40.jpg 10.64MB
516.jpg 10.5MB
383.jpg 10.45MB
920.jpg 10.36MB
945.jpg 10MB
709.jpg 9.95MB
272.jpg 9.4MB
903.jpg 9.05MB
524.jpg 8.29MB
403.jpg 7.79MB
99.jpg 7.31MB
139.jpg 5.78MB
45.jpg 5.67MB
827.jpg 5.47MB
878.jpg 5.43MB
702.jpg 5.35MB
411.jpg 5.35MB
268.jpg 5.31MB
314.jpg 5.26MB
465.jpg 5.23MB
713.jpg 5.13MB
41.jpg 4.77MB
326.jpg 4.74MB
333.jpg 4.43MB
599.jpg 4.21MB
123.jpg 3.96MB
632.jpg 3.9MB
394.jpg 3.77MB
87.jpg 3.44MB
914.jpg 3.03MB
570.jpg 2.96MB
473.jpg 2.11MB
366.jpg 2.04MB
817.jpg 1.63MB
928.jpg 1.63MB
1002.jpg 1.43MB
bus.jpg 476KB
239.jpg 315KB
74.jpg 260KB
644.jpg 200KB
509.jpg 197KB
80.jpg 167KB
270.jpg 163KB
6.jpg 156KB
128.jpg 150KB
458.jpg 150KB
876.jpg 145KB
715.jpg 145KB
991.jpg 143KB
369.jpg 143KB
44.jpg 141KB
bus.jpg 134KB
ski.jpg 131KB
12.jpg 126KB
259.jpg 124KB
888.jpg 123KB
1024.jpg 120KB
289.jpg 120KB
884.jpg 120KB
550.jpg 119KB
324.jpg 119KB
488.jpg 119KB
656.jpg 117KB
275.jpg 115KB
453.jpg 115KB
554.jpg 110KB
451.jpg 109KB
313.jpg 108KB
749.jpg 106KB
46.jpg 106KB
1001.jpg 105KB
1029.jpg 103KB
492.jpg 103KB
177.jpg 103KB
614.jpg 103KB
121.jpg 103KB
932.jpg 101KB
602.jpg 101KB
723.jpg 101KB
307.jpg 100KB
81.jpg 100KB
895.jpg 99KB
412.jpg 99KB
192.jpg 97KB
27.jpg 97KB
555.jpg 97KB
879.jpg 96KB
748.jpg 96KB
768.jpg 95KB
790.jpg 92KB
592.jpg 92KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- J13141682024-12-28感谢资源主的分享,这个资源对我来说很有用,内容描述详尽,值得借鉴。
stsdddd
- 粉丝: 3w+
- 资源: 985
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于微信小程序的员工日志管理信息系统设计与实现.docx
- 基于微信小程序的校园心声墙小程序设计与实现.docx
- Visual Studio Code 的命令行界面 (CLI)详细介绍.pdf
- python-7.异常BMI输入-该胖胖,该瘦瘦.py
- 基于微信小程序的中医“知源”小程序设计与实现.docx
- python-8.字符串转换-你的类型.py
- 模式识别matlab源码
- python-9.urllib.request请求读取网页-我爬爬爬.py
- 金融贷款审批预测数据.zip
- 基于极限学习机(ELM)的数据回归预测 matlab代码
- 在现代计算机视觉和图像处理领域,图形用户界面(GUI)的应用越来越广泛 Python 的 Tkinter 库提供了一种简单而强大的方式来创建 GUI 应用程序 本课程设计的目标是通过 Tkinter
- 快手小程序模板企业官方专用小程序模板源代码
- 基于卷积-长短期记忆网络(CNN-LSTM)的数据分类预测 matlab代码,要求2019A及以上版本
- 基于门控循环单元网络(GRU)的时间序列预测 matlab代码,要求2019版本及以上
- IOI1998矩形周长加强版数据闲人勿下
- 易飞ERP 9.2 安装包 百度云盘 下载
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功