Add polygon regions drawing support in `object-counting.md` and minor docs update (#8885)

pull/8861/head
Muhammad Rizwan Munawar 1 year ago committed by GitHub
parent 3623d62ea8
commit 014f0b4b8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 47
      docs/en/guides/object-counting.md
  2. 1
      docs/en/index.md

@ -36,7 +36,7 @@ Object counting with [Ultralytics YOLOv8](https://github.com/ultralytics/ultraly
!!! Example "Object Counting using YOLOv8 Example"
=== "Region"
=== "Count in Region"
```python
from ultralytics import YOLO
@ -78,8 +78,51 @@ Object counting with [Ultralytics YOLOv8](https://github.com/ultralytics/ultraly
video_writer.release()
cv2.destroyAllWindows()
```
=== "Count in Polygon"
=== "Line"
```python
from ultralytics import YOLO
from ultralytics.solutions import object_counter
import cv2
model = YOLO("yolov8n.pt")
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 as a polygon with 5 points
region_points = [(20, 400), (1080, 404), (1080, 360), (20, 360), (20, 400)]
# Video writer
video_writer = cv2.VideoWriter("object_counting_output.avi",
cv2.VideoWriter_fourcc(*'mp4v'),
fps,
(w, h))
# Init Object Counter
counter = object_counter.ObjectCounter()
counter.set_args(view_img=True,
reg_pts=region_points,
classes_names=model.names,
draw_tracks=True)
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or video processing has been successfully completed.")
break
tracks = model.track(im0, persist=True, show=False)
im0 = counter.start_counting(im0, tracks)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
```
=== "Count in Line"
```python
from ultralytics import YOLO

@ -69,6 +69,7 @@ Explore the YOLOv8 Docs, a comprehensive resource designed to help you understan
- [YOLOv6](https://github.com/meituan/YOLOv6) was open-sourced by [Meituan](https://about.meituan.com/) in 2022 and is in use in many of the company's autonomous delivery robots.
- [YOLOv7](https://github.com/WongKinYiu/yolov7) added additional tasks such as pose estimation on the COCO keypoints dataset.
- [YOLOv8](https://github.com/ultralytics/ultralytics) is the latest version of YOLO by Ultralytics. As a cutting-edge, state-of-the-art (SOTA) model, YOLOv8 builds on the success of previous versions, introducing new features and improvements for enhanced performance, flexibility, and efficiency. YOLOv8 supports a full range of vision AI tasks, including [detection](tasks/detect.md), [segmentation](tasks/segment.md), [pose estimation](tasks/pose.md), [tracking](modes/track.md), and [classification](tasks/classify.md). This versatility allows users to leverage YOLOv8's capabilities across diverse applications and domains.
- [YOLOv9] (https://github.com/WongKinYiu/yolov9) Introduces innovative methods like Programmable Gradient Information (PGI) and the Generalized Efficient Layer Aggregation Network (GELAN).
## YOLO Licenses: How is Ultralytics YOLO licensed?

Loading…
Cancel
Save