Are you sure you want to delete this access key?
comments | description | keywords |
---|---|---|
true | Learn how to use Ultralytics YOLO11 for precise object counting in specified regions, enhancing efficiency across various applications. | object counting, regions, YOLO11, computer vision, Ultralytics, efficiency, accuracy, automation, real-time, applications, surveillance, monitoring |
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.
Watch: Object Counting in Different Regions using Ultralytics YOLO11 | Ultralytics Solutions 🚀
Retail | Market Streets |
---|---|
![]() |
![]() |
People Counting in Different Region using Ultralytics YOLO11 | Crowd Counting in Different Region using Ultralytics YOLO11 |
!!! example "Region counting using Ultralytics YOLO"
=== "Python"
```python
import cv2
from ultralytics import solutions
cap = cv2.VideoCapture("path/to/video.mp4")
assert cap.isOpened(), "Error reading video file"
# Pass region as list
# region_points = [(20, 400), (1080, 400), (1080, 360), (20, 360)]
# 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
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
video_writer = cv2.VideoWriter("region_counting.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Initialize region counter object
regioncounter = solutions.RegionCounter(
show=True, # display the frame
region=region_points, # pass region points
model="yolo11n.pt", # model for counting in regions i.e yolo11s.pt
)
# Process video
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or processing is complete.")
break
results = regioncounter(im0)
# print(results) # access the output
video_writer.write(results.plot_im)
cap.release()
video_writer.release()
cv2.destroyAllWindows() # destroy all opened windows
```
!!! tip "Ultralytics Example Code"
The Ultralytics region counting module is available in our [examples section](https://github.com/ultralytics/ultralytics/blob/main/examples/YOLOv8-Region-Counter/yolov8_region_counter.py). You can explore this example for code customization and modify it to suit your specific use case.
RegionCounter
ArgumentsHere's a table with the RegionCounter
arguments:
{% from "macros/solutions-args.md" import param_table %} {{ param_table(["model", "region"]) }}
The RegionCounter
solution enables the use of object tracking parameters:
{% from "macros/track-args.md" import param_table %} {{ param_table(["tracker", "conf", "iou", "classes", "verbose", "device"]) }}
Additionally, the following visualization settings are supported:
{% from "macros/visualization-args.md" import param_table %} {{ param_table(["show", "line_width", "show_conf", "show_labels"]) }}
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.
Follow these steps to run object counting in Ultralytics YOLO11:
Clone the Ultralytics repository and navigate to the directory:
git clone https://github.com/ultralytics/ultralytics
cd ultralytics/examples/YOLOv8-Region-Counter
Execute the region counting script:
python yolov8_region_counter.py --source "path/to/video.mp4" --save-img
For more options, visit the Usage Examples section.
Using Ultralytics YOLO11 for object counting in regions offers several advantages:
Explore deeper benefits in the Advantages section.
Object counting with Ultralytics YOLO11 can be applied to numerous real-world scenarios:
Explore more examples in the Real World Applications section and the TrackZone solution for additional zone-based monitoring capabilities.
Press p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?