# 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多类别口罩检测训练权重, 3000多千张多类别口罩检测数据集,数据集目录已经配置好,yolo格式(txt)的标签,划分好 train,val, test,并附有data.yaml文件,yolov5、yolov7、yolov8等算法可以直接进行训练模型, qt界面可以 检测图片、视频和调用摄像头,有相应的选择项 采用pytrch框架,代码是python的 数据集和检测结果参考: https://blog.csdn.net/zhiqingAI/article/details/124230743 数据集配置目录结构data.yaml: train: ../train/images val: ../valid/images test: ../test/images nc: 8 names: ['cloth', 'kn95', 'mask', 'mask_weared_incorrect', 'n95', 'surgical', 'with_mask', 'without_mask']
资源推荐
资源详情
资源评论
收起资源包目录
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
3468p_png_jpg.rf.f090917410232134579b9e20ee0a6d40.txt 618B
1t-116-_cloth_jpg.rf.6afa8cdb83ec6552e48165a26d95162f.txt 613B
3468p_png_jpg.rf.40f8d4c65cf3a135af488c389738795c.txt 613B
3468p_png_jpg.rf.392c0cbeb88f615241e64e8c39f66b2f.txt 613B
3468p_png_jpg.rf.c16a5a352a985a491148094147590c3e.txt 613B
1t-116-_cloth_jpg.rf.2b6c9087cdbebeb3e6c5a95aa724655f.txt 605B
1t-116-_cloth_jpg.rf.0306481fc76bf546340d502356f2a69c.txt 605B
1t-116-_cloth_jpg.rf.e028c916568ed5df4c31ce55357472cc.txt 604B
1t-116-_cloth_jpg.rf.b96ac6feb3d8d036121faa022efe25ca.txt 604B
1t-116-_cloth_jpg.rf.d3dac73f6afbfb28f3ce527d31163617.txt 600B
1t-116-_cloth_jpg.rf.9353c61ee8ebdf7ce1f859d958917271.txt 598B
jjjjj-172-_cloth_png_jpg.rf.7291a67f78f288c76735d7a18db66c44.txt 514B
jjjjj-172-_cloth_png_jpg.rf.4f6bc5dff86a9ff9eceb3c34eb6b7323.txt 514B
61162_surgical_green_jpg.rf.80e2ba1393bc11e6482acaf40f5dd8cb.txt 502B
61162_surgical_green_jpg.rf.0710f653b5b51d9cc24babfdc4cc92b3.txt 498B
61162_surgical_green_jpg.rf.ad7195aa581677876a2b54d8a35716e4.txt 498B
angry-24-_jpg.rf.2cec6c7e81d876b5c1fde8ea28cccf57.txt 488B
angry-24-_jpg.rf.794f0f2774372366713bdbc61fe8d3b6.txt 487B
angry-24-_jpg.rf.f63ad005062602d5fc7a852ee0ba9ee6.txt 487B
326829_cloth_jpg.rf.1d61e0a2ecc6922708ad2ac8aab8d95c.txt 484B
326829_cloth_jpg.rf.40a0567dac52ec8f9dc4e9f7749e94c1.txt 470B
61303_surgical_blue_jpg.rf.dbd6e64786093db56e2603b1d334117a.txt 470B
61303_surgical_blue_jpg.rf.57960346dae806edc5974f8ef667bbe5.txt 470B
10253_empty_jpg.rf.ae97dc11e33c5e6813a7d3026b2f61e8.txt 435B
326829_cloth_jpg.rf.fc5d8977c3913472e680627250a1b9a0.txt 433B
326829_cloth_jpg.rf.d59742041ef599494fcdb4cfb116158c.txt 433B
2016j_jpg.rf.d0eab157e0ba76da41b94aaa80d989f0.txt 432B
2016j_jpg.rf.004ece4cc28b2e9083dd07edb79170e3.txt 432B
2016j_jpg.rf.1301adedbd1cb358c8979158d2c331db.txt 431B
326829_cloth_jpg.rf.b46b3e41c7e4d2df72abf8f6213d12b5.txt 431B
2016j_jpg.rf.b5d5aa12cb60246a3b577a5348228e46.txt 431B
2016j_jpg.rf.c9e32032ed5e5254020d02e35f8fb110.txt 431B
2016j_jpg.rf.96ed2efbce3cf78029746e237f9eff81.txt 431B
1t-128-_cloth_jpg.rf.a7a75164dddf3c20bc0454aacc4f47fe.txt 402B
1t-128-_cloth_jpg.rf.00fd682f1e729ad6297b96b01ca7791b.txt 377B
1t-128-_cloth_jpg.rf.c52aa35d15f874175ccbfb3de4bd51b0.txt 374B
1t-128-_cloth_jpg.rf.49f8f045601fc612733d2c7cb4ec15d2.txt 368B
10253_empty_jpg.rf.46d4065b742973e7f9f5d93f57a8a5a5.txt 361B
10253_empty_jpg.rf.78e2f10b104ecf7581481e2b6c83aa4b.txt 361B
1953j_jpg.rf.f9feedfca0040394dbbbbb12bf11d649.txt 323B
1953j_jpg.rf.d3cd905947ffaed7d55f409110d5df78.txt 323B
1953j_jpg.rf.2d771f213b79dfc4e25879438edb9e65.txt 314B
4826p_png_jpg.rf.030c32191258f196fddf3129fb62f5b5.txt 312B
4826p_png_jpg.rf.36978c2239b3032cc02197cfa7648330.txt 300B
4826p_png_jpg.rf.a4f8d62d7541de547277b2bfefaf4f32.txt 300B
4368p_png_jpg.rf.2d540c257842be1773ced0f79876afb4.txt 281B
4368p_png_jpg.rf.0b551011a3939589bd94360459bae5e7.txt 281B
4368p_png_jpg.rf.3fb006f2aedcbc4abbd925bbad523549.txt 281B
4368p_png_jpg.rf.136ce4c894d1eb73305e304198a7a866.txt 281B
5263j_jpg.rf.24095f79210f1c75727178dd0530532a.txt 275B
5263j_jpg.rf.39371e49b15ccd230cc3e1040bffc3d8.txt 270B
5263j_jpg.rf.68a96593aae59246b814a0da599074ba.txt 270B
5263j_jpg.rf.716e53269678244f96cdd8e9df239570.txt 270B
2151j_jpg.rf.1da6be1fea60008d5009fc022d796b63.txt 265B
2151j_jpg.rf.1ddc9102b4d5542d46abc8ede4ef1584.txt 265B
2278p_png_jpg.rf.0407877703f14fdfaf9a96c12d8e363d.txt 261B
2278p_png_jpg.rf.bc7a8afa48aa85f4e344a65506b4caf2.txt 261B
2278p_png_jpg.rf.95135750b9cc72723722580d8145f213.txt 261B
2278p_png_jpg.rf.b06ee83e4d7831d3214ad950ea31255c.txt 260B
2151j_jpg.rf.b5ee5bf402a1c877b3c53186756a443c.txt 255B
2151j_jpg.rf.f79fa1d7534a9c426eea5edffc1fe188.txt 255B
3376p_png_jpg.rf.d5fe0bcaa29319386a64b7fd5422ae4a.txt 237B
3376p_png_jpg.rf.55f9e0f075cd7437e44e901d9339aec6.txt 237B
3376p_png_jpg.rf.3e8b1ccea81b229043a9e7aa22c29a88.txt 235B
3376p_png_jpg.rf.64ebc0371c9625811b7f1076604cb1de.txt 235B
3376p_png_jpg.rf.f348af5ad76019f77500e6fd945ffcdc.txt 235B
DoubleRow_png_jpg.rf.0a936b7cf207f62df5d950fa1737acb1.txt 235B
DoubleRow_png_jpg.rf.3977f37a2c5787ec1c22e9545a3c2e18.txt 235B
4325p_png_jpg.rf.d4a4b09d28dbe32a53d9a52a56d02374.txt 234B
2092j_jpg.rf.507247f8a35bfc406bfe4f5fceb32074.txt 233B
2092j_jpg.rf.636261d179254b6c89369ee7d14c8482.txt 233B
2092j_jpg.rf.62bdc3dc39e81ff71e0e0f9e9439b182.txt 233B
2092j_jpg.rf.f1dcce377ea8d84146efe51db866448e.txt 232B
4325p_png_jpg.rf.c50aca8efddb3dd96247829caf93e998.txt 231B
DoubleRow_png_jpg.rf.6af2c25196c087f470b59c33af07beb4.txt 226B
DoubleRow_png_jpg.rf.0010b16ac560a779be6e705b75961e89.txt 226B
3735p_png_jpg.rf.4661f04407c5ea87392044a8f801c422.txt 223B
3735p_png_jpg.rf.6576872eebfc629b90428bcf8c9664f8.txt 222B
3648p_png_jpg.rf.1694980d2c24237a4f948a7541d95255.txt 218B
3648p_png_jpg.rf.d9b8df28ffa23138606805c53f9c69c1.txt 218B
3648p_png_jpg.rf.8e3eaa14592c2335a5a5b940bae7bd40.txt 218B
3648p_png_jpg.rf.10ab22a45ed53a9944ea12ae24009a90.txt 218B
3648p_png_jpg.rf.dc39879f4ed035bffda26ea17b36f9ec.txt 218B
4776p_png_jpg.rf.4cc908e5da73bf0adfc4c4350f621520.txt 206B
4776p_png_jpg.rf.a139088f757ad93b38f0512097e5782b.txt 206B
4776p_png_jpg.rf.8b7ed4a31760715736f16bc950d24fe1.txt 203B
4776p_png_jpg.rf.c584944a0f15fc011d89526f01fba4fd.txt 203B
3640p_png_jpg.rf.8d62002b2a62785ea2d6a461a5ba0031.txt 198B
3893p_png_jpg.rf.65fb5ae404cf402b0904977ffc8dc72a.txt 198B
3893p_png_jpg.rf.09ee838d7900b4522e01ce0223005987.txt 198B
3893p_png_jpg.rf.f48966892d31517bfb896d7a90805c62.txt 198B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
stsdddd
- 粉丝: 2w+
- 资源: 686
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功