Ultralytics Solutions:利用 YOLO26 解决现实世界的问题
Ultralytics Solutions 是基于 Ultralytics YOLO 模型构建的即用型应用,用于解决常见的计算机视觉问题,例如目标计数、热力图和速度估算、队列管理和目标模糊处理。大多数解决方案会将检测、跟踪或姿态估计封装在可配置的类中,你可以通过 Python 或 yolo solutions CLI 运行这些类。

观看: 如何从命令行运行 Ultralytics Solutions (CLI) | Ultralytics YOLO26 🚀
解决方案#
以下每个解决方案都有专属指南:
- 分析:根据 YOLO26 检测结果生成折线图、柱状图、饼图和面积图,以分析趋势随时间的变化。
- 距离计算:在 YOLO26 中使用边界框质心计算对象之间的距离,进行空间分析。
- 热力图:将 YOLO26 检测结果累积到热力图叠加层中,显示对象最常出现或移动的位置。
- 实例分割与目标跟踪:结合 YOLO26 的实例分割和目标跟踪,在视频帧之间跟踪对象轮廓。
- 使用 Streamlit 进行实时推理:通过 Streamlit 界面,在网页浏览器中使用 YOLO26 运行实时目标检测。
- 物体模糊处理:使用 YOLO26 对物体进行模糊处理,保护图像和视频处理中的隐私。
- 目标计数:使用 YOLO26 统计视频和实时流中穿过线条或进入区域的对象。
- 区域内目标计数:使用 YOLO26 统计多个用户定义区域内的对象。
- 目标裁剪:使用 YOLO26 从图像和视频中裁剪检测到的对象,并将每个对象单独保存为图像。
- OCR:使用 YOLO26-Text 检测器和 PP-OCRv6 识别模型,检测、识别并按顺序输出任意旋转角度下的场景文本和文档文本;也可以使用 PP-OCRv5 语言模型读取韩文、西里尔文、阿拉伯文和其他文字。
- 停车场管理:使用 YOLO26 监控已占用和可用的停车位。
- 队列管理:使用 YOLO26 统计在队列区域内等待的人数,以监控队列长度。
- 安全警报系统:使用 YOLO26 构建安全警报系统,当检测到的对象数量达到阈值时发送电子邮件警报。
- 相似性搜索:结合 OpenAI CLIP 嵌入和余弦相似性搜索,通过“拿着包的人”或“行驶中的车辆”等自然语言查询检索图像。
- 速度估算:使用 YOLO26 和目标跟踪估算对象速度,适用于交通监测等应用。
- 跟踪区域内的对象:使用 YOLO26 仅跟踪视频帧指定区域内的对象。
- VisionEye 视角对象映射:将检测到的对象与固定观察点关联,模拟人眼聚焦特定对象的方式。
- 锻炼监测:使用 YOLO26 姿态估计实时统计锻炼次数并跟踪锻炼阶段。
解决方案参数#
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
model | str | None | Ultralytics YOLO 模型文件的路径。 |
region | list 或 dict | None | 定义感兴趣区域的点,可以是 (x, y) 元组列表,也可以是将区域名称映射到点列表的字典(仅支持多个 RegionCounter 区域)。如果为 None,则需要区域的解决方案会退回到预定义的默认区域。 |
show_in | bool | True | 控制是否在视频流中显示流入计数的标志。 |
show_out | bool | True | 控制是否在视频流中显示流出计数的标志。 |
analytics_type | str | 'line' | 图表类型,即 line、bar、area 或 pie。 |
colormap | int | cv2.COLORMAP_DEEPGREEN | 要用于热力图的颜色映射。 |
line_width | int | 2 | 解决方案绘制的框、关键点和计数的线条粗细。 |
verbose | bool | True | 启用逐帧日志,记录输入形状、类别计数和处理速度。跟踪调用本身始终不会输出日志。 |
json_file | str | None | 包含所有停车位坐标数据的 JSON 文件路径。 |
up_angle | float | 145.0 | “向上”姿势的角度阈值。 |
kpts | list[int] | [6, 8, 10] | 用于监测锻炼动作的三个关键点索引组成的列表。这些关键点对应身体关节或部位,例如肩部、肘部和手腕,可用于俯卧撑、引体向上、深蹲和腹部锻炼等动作。 |
down_angle | float | 90.0 | “向下”姿势的角度阈值。 |
blur_ratio | float | 0.5 | 调整模糊强度百分比,取值范围为 0.1 - 1.0。 |
crop_dir | str | 'cropped-detections' | 用于存储裁剪后检测结果的目录名称。 |
records | int | 5 | 触发安全警报系统发送邮件所需的检测总数。 |
vision_point | tuple[int, int] | (20, 20) | 视觉系统使用 VisionEye Solution 跟踪对象并绘制路径的位置。 |
source | str | None | 输入源的路径(视频、RTSP 等)。仅适用于 Solutions 命令行界面 (CLI)。 |
figsize | tuple[float, float] | (12.8, 7.2) | Analytics 图表的图幅尺寸(英寸);(12.8, 7.2) 会渲染 1280×720 的帧。 |
fps | float | 30.0 | 用于速度计算的每秒帧数。 |
max_hist | int | 5 | 每个对象用于速度/方向计算的最大历史跟踪点数。 |
meter_per_pixel | float | 0.05 | 用于将像素距离转换为实际单位的缩放系数。 |
max_speed | int | 120 | 最高速度(km/h);估算速度超过此值时将按此值封顶。 |
data | str | 'images' | 用于相似性搜索的图像目录路径。 |
imgsz | int | 640 | 模型推理的输入图像尺寸。 |
recognizer | str 或 Callable | 'paddleocr' | 文本识别后端:'paddleocr'(在 ONNX Runtime 上运行的 PP-OCRv6)、'tensorrt'(在 NVIDIA GPU 上以 FP16 TensorRT 引擎运行的 PP-OCRv6)、类似 'korean_PP-OCRv5_mobile_rec' 的 PaddleOCR 语言模型名称,或接受 BGR 裁剪图像并返回 (text, confidence) 的可调用对象。 |
解决方案会将以下推理和跟踪参数传递给 model.track()。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
tracker | str | 'tracktrack.yaml' | 指定要使用的跟踪算法。内置选项:botsort.yaml、bytetrack.yaml、ocsort.yaml、deepocsort.yaml、fasttrack.yaml、tracktrack.yaml。 |
conf | float | 0.25 | 设置检测的置信度阈值;较低的值允许跟踪更多物体,但可能会包含误检。 |
iou | float | 0.5 | 设置用于筛除重叠检测结果的交并比 (IoU) 阈值。 |
classes | list | None | 按类别索引筛选结果。例如,classes=[0, 2, 3] 只跟踪指定类别。 |
device | str | None | 指定推理设备(例如 cpu、cuda:0 或 0)。用户可以选择 CPU、特定 GPU 或其他计算设备来运行模型。 |
imgsz | int or tuple | 640 | 目标推理图像尺寸:正方形图像使用整数,或使用 (height, width) 对。图像尺寸会调整为模型步幅的整数倍。 |
max_det | int | 300 | 跟踪前每帧保留的最大检测数量,用于限制解决方案在密集场景中处理的物体数量。 |
quantize | int or str | None | 推理精度:对于非 CPU 上运行的 PyTorch 和 TorchScript 模型,使用 16 (FP16) 或 32/unset (FP32) 进行选择;其他格式使用其模型文件和运行时所选的精度。此参数替代已弃用的 half 参数。 |
你可以使用 show_conf、show_labels 及其他提到的参数来自定义可视化效果。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
show | bool | False | 如果 True,则在窗口中显示带标注的图像或视频。适用于在开发或测试期间即时查看结果。 |
show_conf | bool | True | 在每个检测结果的标签旁显示置信度分数,帮助了解模型对该检测结果的确信程度。 |
show_labels | bool | True | 在可视化输出中显示每个检测结果的标签,便于立即了解检测到的对象。 |
使用 SolutionAnnotator#
所有 Ultralytics Solutions 都使用 SolutionAnnotator 类,该类扩展了主 Annotator 类,并提供以下方法:
| 方法 | 返回类型 | 说明 |
|---|---|---|
draw_region() | None | 使用指定的点、颜色和线宽绘制区域。 |
queue_counts_display() | None | 显示指定区域内的队列计数。 |
display_analytics() | None | 显示停车场管理的整体统计数据。 |
estimate_pose_angle() | float | 计算物体姿态中三个点之间的角度。 |
draw_specific_kpts() | np.ndarray | 在图像上绘制指定关键点。 |
plot_workout_information() | int | 在图像上绘制带标签的文本框。 |
plot_angle_and_count_and_stage() | None | 可视化锻炼监测中的角度、步数和阶段。 |
plot_distance_and_line() | None | 显示质心之间的距离,并用线段连接质心。 |
display_objects_labels() | None | 为边界框标注物体类别标签。 |
sweep_annotator() | None | 可视化垂直扫描线和可选标签。 |
visioneye() | None | 将物体质心映射并连接到可视化的“眼睛”点。 |
adaptive_label() | None | 在边界框中心绘制圆形或矩形背景标签。 |
使用 SolutionResults#
除相似性搜索外,每个解决方案在调用时都会返回一个 SolutionResults 对象。
- 对于目标计数,结果包括
in_count、out_count和classwise_count。
import cv2
from ultralytics import solutions
im0 = cv2.imread("path/to/img")
region_points = [(20, 400), (1080, 400), (1080, 360), (20, 360)]
counter = solutions.ObjectCounter(
show=True, # 显示输出
region=region_points, # 传入区域点
model="yolo26n.pt", # model="yolo26n-obb.pt" 用于使用 OBB 模型进行目标计数。
# classes=[0, 2], # 使用 COCO 预训练模型时,只统计指定类别,例如人和汽车。
# tracker="botsort.yaml" # 选择跟踪器,例如 "bytetrack.yaml"
)
results = counter(im0)
print(results.in_count) # display in_counts
print(results.out_count) # display out_counts
print(results.classwise_count) # display classwise_countSolutionResults 对象具有以下属性:
| 属性 | 类型 | 说明 |
|---|---|---|
plot_im | np.ndarray | 带有计数、模糊效果或特定解决方案增强效果等可视化叠加层的图像。 |
in_count | int | 在视频流中检测到进入所定义区域的物体总数。 |
out_count | int | 在视频流中检测到离开所定义区域的物体总数。 |
classwise_count | dict[str, dict[str, int] | int] | 每个类别的计数:ObjectCounter 和 Heatmap 使用 {"IN": int, "OUT": int},Analytics 使用 int。 |
queue_count | int | 预定义队列或等待区域内当前的物体数量(适用于队列管理)。 |
workout_count | list[int] | AI Gym 中每条跟踪轨迹的锻炼重复次数(每个当前跟踪的个体对应一条记录)。 |
workout_angle | list[float] | AI Gym 中每条跟踪轨迹的运动角度(每个当前跟踪的个体对应一条记录)。 |
workout_stage | list[str] | AI Gym 中每条跟踪轨迹当前的锻炼阶段(每个当前跟踪的个体对应一条记录)。 |
pixels_distance | float | 两个对象或点之间基于像素的距离,例如边界框之间的距离(适用于距离计算)。 |
available_slots | int | 监控区域内的空闲车位数量(适用于停车管理)。 |
filled_slots | int | 监控区域内已占用车位的数量(适用于停车场管理)。 |
email_sent | bool | 指示通知或警报邮件是否已成功发送(适用于安防报警)。 |
total_tracks | int | 视频分析期间观察到的唯一目标轨迹总数。 |
region_counts | dict[str, int] | 用户自定义区域或分区内的对象数量。 |
speed_dict | dict[int, int] | 按跟踪 ID 分类的字典,包含 SpeedEstimator 估算的对象速度(单位:km/h),适用于速度分析。 |
total_crop_objects | int | ObjectCropper 解决方案生成的裁剪对象图像总数。 |
speed | dict[str, float] | 包含跟踪和解决方案处理性能指标的字典。 |
如需了解更多详情,请参阅 SolutionResults 类文档。
通过 CLI 使用解决方案#
大多数解决方案都可以直接通过命令行界面运行。
语法
yolo SOLUTIONS SOLUTION_NAME ARGS
- SOLUTIONS 是必需的关键字。
- SOLUTION_NAME 可以是以下值之一:
['count', 'crop', 'blur', 'workout', 'heatmap', 'isegment', 'queue', 'speed', 'analytics', 'trackzone', 'inference', 'visioneye', 'region', 'security', 'parking']。 - ARGS(可选)是自定义的
arg=value键值对,例如show_in=True,用于覆盖默认设置。
yolo solutions count show=True # for object counting
yolo solutions count source="path/to/video.mp4" # specify video file path为我们的解决方案贡献力量#
欢迎社区贡献。如果你使用 Ultralytics YOLO 构建了此处尚未介绍的解决方案,可以考虑将其分享为指南,让其他用户也能受益。
常见问题#
Ultralytics YOLO26 通过结合检测和跟踪来实时统计对象,因此每个对象在穿过线条或进入区域时只会被计数一次。要设置 YOLO26 以分析实时视频流,请安装
ultralytics,加载模型,并将视频帧传递给solutions.ObjectCounter。Ultralytics YOLO26 为基于摄像头的安全系统添加了实时目标检测和警报功能。借助安全警报系统解决方案,当监控区域内检测到的对象数量达到阈值时,YOLO26 会发送电子邮件警报。
Ultralytics YOLO26 统计并跟踪队列区域内的人数,为你提供实时排队人数,帮助缩短等待时间并规划人员配置。
可以。Ultralytics YOLO26 姿态模型可实时跟踪人体关键点,因此锻炼监测解决方案能够测量关节角度、统计锻炼次数,并报告当前锻炼阶段。
评论23
提出问题、分享结果,或帮助其他人。
ZHIYUAN816(已编辑)
But acturally I don't konw how to set plots_max
Glenn JocherUltralytics(已编辑)@ZHIYUAN816 you don't need to set anything: the warning has no effect on training or metrics, only on how many items are drawn on the plotted validation images (optional, for visual review). In current versions that limit follows the
max_detargument (default 300).
ZHIYUAN816
WARNING ⚠️ Limiting validation plots to first 50 items per image for speed... WARNING ⚠️ Limiting validation plots to first 50 items per image for speed... how to solve this problem bro?
Glenn JocherUltralytics(已编辑)@ZHIYUAN816 this is not an error but a warning that the plotted prediction images are limited to a maximum number of items per image. It does not affect training. In current versions the limit follows
max_det(default 300).
smc0927
If I want a target to be detected only once, is it possible? If so, how can I do it?
RizwanMunawar
@smc0927 Hi! I’m not entirely sure I understand your question. Could you please clarify a bit?
Generally, the counting process is designed to occur only once for each track ID. Once an object is counted, it won't be counted again, even if it crosses the same
regionorlinemultiple times.smc0927
ok,I want to print out the coordinates of the target, but that's not what I want because it's going to be printed multiple times over a period of time. I want it to be output only once, is there a way to achieve this?
RizwanMunawar
@smc0927 Yes it's possible. You can simply iterate over the detection results. BTW, this discussion is more related to Ultralytics solutions, while your question is related to prediction :)
Sample Code
from ultralytics import YOLO model = YOLO("yolo11n.pt") results = model.predict("path/to/im0") if results[0].boxes.id is not None: boxes = results[0].boxes.xyxy.cpu() track_ids = results[0].boxes.id.int().cpu().tolist() clss = results[0].boxes.cls.cpu().tolist() for box, cls in enumerate(boxes, clss): # Here you can add the logic to display single-time details of the objectThanks :)
smc0927
sorry
hodat2608
Hi everyone, hi @glenn-jocher, I want to install pycuda on my windows 10 using python 3.12, but I still can't do it. It's hard to find any documentation or tutorials like that, @glenn-jocher or anyone can send me a link or tutorial to install pycuda? Please help me. Thanks first
MuhammedEnesGurkan
hey how can ı find yolo v8 solutions source codes.
Glenn JocherUltralytics@MuhammedEnesGurkan you can find the source codes for YOLOv8 solutions on the Ultralytics GitHub repository. For more detailed guides and examples, please visit the Ultralytics Solutions page at https://docs.ultralytics.com/solutions/.
maxexplorer
Hi there,
After updating Ultralytics and using YOLO11, will the YOLOv8 models still work in this virtual environment?
Thank you in advance for your help and the great work you’re doing!
Glenn JocherUltralytics@maxexplorer yes, YOLOv8 models will continue to work in your virtual environment after updating to YOLO11. If you have further questions, feel free to ask!
yosifsaab
hi i have error during using the google colab for classification two classes images by yolov8n
results = model.train(data=DATA_DIR, epochs=1, imgsz=64)
Glenn JocherUltralytics@yosifsaab it seems you're encountering an error with YOLOv8n in Google Colab. Please ensure your
DATA_DIRis correctly set and that your dataset is properly formatted. If the issue persists, check the Colab notebook for any specific error messages that might provide more details. For further assistance, you can refer to the Ultralytics documentation.
Nkosiyazimelani
Hi guys, how do i update the nc that my model can detect without having to train with old and new objects. i have updated my .YAML file but the model is still detecting the old number of objects(20 instead of 46). i have been told to look on the model itself and change the output number of class to the new updated on but there is nothing of that sort in the model file( best.pt). please help.
Glenn JocherUltralytics(已编辑)@Nkosiyazimelani the number of classes (
nc) is part of the trained model's detection head, so editing the.yamlfile after training doesn't change whatbest.ptpredicts. You need to train again with a dataset YAML that has all 46 classes. You don't have to start from scratch, you can fine-tune from your existing weights, and the layers whose shapes depend on the class count are reinitialized automatically:from ultralytics import YOLO model = YOLO("best.pt") model.train(data="your_46_class_dataset.yaml", epochs=100)Make sure your dataset contains labeled examples of both the old and the new classes, otherwise the model will forget the old ones.
nounotabe
How to specify the device to be used (e.g. cuda:1)?
Glenn JocherUltralytics@nounotabe to specify the device for running YOLOv8, you can use the
deviceargument. For example, to use the second GPU (cuda:1), you can setdevice='cuda:1'. This can be done in both the CLI and Python API. If you encounter any issues, please ensure you are using the latest version of the package. For more detailed guidance, you can refer to our documentation at https://docs.ultralytics.com.cobaltautomationdev
lasted version of ultralytics. solutions not works in Windows10, but works in Google Colab. What's wrong with it? How to settle it? from ultralytics import solutions,YOLO , Couldn't import solutions in my windows10.
Glenn JocherUltralyticsIt seems like there might be an issue with the
solutionsmodule on Windows 10. Please ensure you are using the latest version of the Ultralytics package. If the issue persists, try reinstalling the package or running the code in a different environment. For further assistance, you can refer to our documentation at https://docs.ultralytics.com/solutions/.cobaltautomationdev
Just updated to v8.2.78 today ,uninstall and reinstall the latest version. and now it works on Windows10 . it seems there something changed in solutions init.py . this file caused import error in previous version. I noticed that in version 8.2.0, file init.py is blank. now add some code in it.