跳至内容

使用Ultralytics YOLO 🚀 对不同区域的物体进行计数

什么是区域对象计数?

Object counting in regions with Ultralytics YOLO11 involves precisely determining the number of objects within specified areas using advanced computer vision. This approach is valuable for optimizing processes, enhancing security, and improving efficiency in various applications.



观看: 使用Ultralytics YOLO11 |Ultralytics 解决方案在不同区域对物体进行计数 🚀

区域对象计数的优势?

  • 精确和准确:利用先进的计算机视觉技术在区域内进行物体计数,可确保计数的精确性和准确性,最大限度地减少人工计数经常出现的误差。
  • 提高效率:自动对象计数可提高运行效率,提供实时结果并简化不同应用的流程。
  • 多样性和应用:区域物体计数的多功能性使其适用于从制造和监控到交通监控等各个领域,从而使其具有广泛的实用性和有效性。

真实世界的应用

零售 市场街道
People Counting in Different Region using Ultralytics YOLO11 Crowd Counting in Different Region using Ultralytics YOLO11
People Counting in Different Region using Ultralytics YOLO11 Crowd Counting in Different Region using Ultralytics YOLO11

区域计数示例

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

# Define region points
# region_points = [(20, 400), (1080, 400), (1080, 360), (20, 360)] # Pass region as list

# pass region as dictionary
region_points = {
    "region-01": [(50, 50), (250, 50), (250, 250), (50, 250)],
    "region-02": [(640, 640), (780, 640), (780, 720), (640, 720)],
}

# Video writer
video_writer = cv2.VideoWriter("region_counting.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

# Init RegionCounter
region = solutions.RegionCounter(
    show=True,
    region=region_points,
    model="yolo11n.pt",
)

# Process video
while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    im0 = region.count(im0)
    video_writer.write(im0)

cap.release()
video_writer.release()
cv2.destroyAllWindows()

Ultralytics 代码示例

Ultralytics 区域计数模块可在我们的示例部分找到。您可以利用这个示例进行代码定制和修改,以适应您的具体使用情况。

论据 RegionCounter

下面的表格显示了 RegionCounter 争论:

名称 类型 默认值 说明
model str None Ultralytics YOLO 模型文件的路径
region list [(20, 400), (1260, 400)] 定义计数区域的点列表。
line_width int 2 边界框的线条粗细
show bool False 用于控制是否显示视频流的标志。

常见问题

What is object counting in specified regions using Ultralytics YOLO11?

Object counting in specified regions with Ultralytics YOLO11 involves detecting and tallying the number of objects within defined areas using advanced computer vision. This precise method enhances efficiency and accuracy across various applications like manufacturing, surveillance, and traffic monitoring.

How do I run the region based object counting script with Ultralytics YOLO11?

Follow these steps to run object counting in Ultralytics YOLO11:

  1. 克隆Ultralytics 仓库并导航至该目录:

    git clone https://github.com/ultralytics/ultralytics
    cd ultralytics/examples/YOLOv8-Region-Counter
    
  2. 执行区域计数脚本:

    python yolov8_region_counter.py --source "path/to/video.mp4" --save-img
    

有关更多选项,请访问运行区域计数部分。

Why should I use Ultralytics YOLO11 for object counting in regions?

Using Ultralytics YOLO11 for object counting in regions offers several advantages:

  • 精确和准确:最大限度地减少人工计数时经常出现的误差。
  • 提高效率:提供实时结果并简化流程。
  • 多样性和应用性:适用于各种领域,增强了其实用性。

在 "优势"部分探索更深层次的优势。

物体计数在区域中有哪些实际应用?

Object counting with Ultralytics YOLO11 can be applied to numerous real-world scenarios:

  • 零售:计算人流量,进行人流分析。
  • 市场街道:人群密度管理

在 "真实世界应用"部分探索更多示例。

📅创建于 1 年前 ✏️已更新 17 天前

评论