Object Counting using Ultralytics YOLO11
์ค๋ธ์ ํธ ์นด์ดํ ์ด๋ ๋ฌด์์ธ๊ฐ์?
Object counting with Ultralytics YOLO11 involves accurate identification and counting of specific objects in videos and camera streams. YOLO11 excels in real-time applications, providing efficient and precise object counting for various scenarios like crowd analysis and surveillance, thanks to its state-of-the-art algorithms and deep learning capabilities.
Watch: Object Counting using Ultralytics YOLO11 |
Watch: Class-wise Object Counting using Ultralytics YOLO11 |
์ค๋ธ์ ํธ ์นด์ดํ ์ ์ฅ์ ์?
- ๋ฆฌ์์ค ์ต์ ํ: ๊ฐ์ฒด ์นด์ดํ ์ ์ ํํ ๊ฐ์๋ฅผ ์ ๊ณตํ๊ณ ์ฌ๊ณ ๊ด๋ฆฌ์ ๊ฐ์ ์ ํ๋ฆฌ์ผ์ด์ ์์ ๋ฆฌ์์ค ํ ๋น์ ์ต์ ํํ์ฌ ํจ์จ์ ์ธ ๋ฆฌ์์ค ๊ด๋ฆฌ๋ฅผ ์ฉ์ดํ๊ฒ ํฉ๋๋ค.
- ๋ณด์ ๊ฐํ: ๊ฐ์ฒด ์นด์ดํ ์ ๊ฐ์ฒด๋ฅผ ์ ํํ๊ฒ ์ถ์ ํ๊ณ ๊ณ์ฐํ์ฌ ์ฌ์ ์ํ ํ์ง๋ฅผ ์ง์ํจ์ผ๋ก์จ ๋ณด์๊ณผ ๊ฐ์๋ฅผ ๊ฐํํฉ๋๋ค.
- ์ ๋ณด์ ๊ธฐ๋ฐํ ์์ฌ ๊ฒฐ์ : ๊ฐ์ฒด ์นด์ดํ ์ ์์ฌ ๊ฒฐ์ , ์๋งค์ , ๊ตํต ๊ด๋ฆฌ ๋ฐ ๊ธฐํ ๋ค์ํ ์์ญ์ ํ๋ก์ธ์ค ์ต์ ํ๋ฅผ ์ํ ๊ท์คํ ์ธ์ฌ์ดํธ๋ฅผ ์ ๊ณตํฉ๋๋ค.
์ค์ ์ ํ๋ฆฌ์ผ์ด์
๋ฌผ๋ฅ | ์์์ |
---|---|
Conveyor Belt Packets Counting Using Ultralytics YOLO11 | Fish Counting in Sea using Ultralytics YOLO11 |
Object Counting using YOLO11 Example
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, 404), (1080, 360), (20, 360)]
# Video writer
video_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Init Object Counter
counter = solutions.ObjectCounter(
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 = counter.count(im0)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
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))
# line or region points
line_points = [(20, 400), (1080, 400)]
# Video writer
video_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Init Object Counter
counter = solutions.ObjectCounter(
show=True,
region=line_points,
model="yolo11n-obb.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 = counter.count(im0)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
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, 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 = solutions.ObjectCounter(
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 = counter.count(im0)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
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
line_points = [(20, 400), (1080, 400)]
# Video writer
video_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Init Object Counter
counter = solutions.ObjectCounter(
show=True,
region=line_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 = counter.count(im0)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
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))
# Video writer
video_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Init Object Counter
counter = solutions.ObjectCounter(
show=True,
model="yolo11n.pt",
classes=[0, 1],
)
# 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 = counter.count(im0)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
์ธ์ ObjectCounter
๋ค์์ ํ์
๋๋ค. ObjectCounter
์ธ์๋ฅผ ์ฌ์ฉํฉ๋๋ค:
์ด๋ฆ | ์ ํ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
---|---|---|---|
model |
str |
None |
Path to Ultralytics YOLO Model File |
region |
list |
[(20, 400), (1260, 400)] |
๊ณ์ฐ ์์ญ์ ์ ์ํ๋ ํฌ์ธํธ ๋ชฉ๋ก์ ๋๋ค. |
line_width |
int |
2 |
๊ฒฝ๊ณ ์์์ ์ ๋๊ป์ ๋๋ค. |
show |
bool |
False |
๋น๋์ค ์คํธ๋ฆผ ํ์ ์ฌ๋ถ๋ฅผ ์ ์ดํ๋ ํ๋๊ทธ์ ๋๋ค. |
show_in |
bool |
True |
๋น๋์ค ์คํธ๋ฆผ์ ์ธ ์นด์ดํธ๋ฅผ ํ์ํ ์ง ์ฌ๋ถ๋ฅผ ์ ์ดํ๋ ํ๋๊ทธ์ ๋๋ค. |
show_out |
bool |
True |
๋น๋์ค ์คํธ๋ฆผ์ ์์ ์นด์ดํธ๋ฅผ ํ์ํ ์ง ์ฌ๋ถ๋ฅผ ์ ์ดํ๋ ํ๋๊ทธ์ ๋๋ค. |
์ธ์ model.track
์ธ์ | ์ ํ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
---|---|---|---|
source |
str |
None |
Specifies the source directory for images or videos. Supports file paths and URLs. |
persist |
bool |
False |
Enables persistent tracking of objects between frames, maintaining IDs across video sequences. |
tracker |
str |
botsort.yaml |
Specifies the tracking algorithm to use, e.g., bytetrack.yaml ๋๋ botsort.yaml . |
conf |
float |
0.3 |
Sets the confidence threshold for detections; lower values allow more objects to be tracked but may include false positives. |
iou |
float |
0.5 |
Sets the Intersection over Union (IoU) threshold for filtering overlapping detections. |
classes |
list |
None |
Filters results by class index. For example, classes=[0, 2, 3] only tracks the specified classes. |
verbose |
bool |
True |
Controls the display of tracking results, providing a visual output of tracked objects. |
์์ฃผ ๋ฌป๋ ์ง๋ฌธ
How do I count objects in a video using Ultralytics YOLO11?
To count objects in a video using Ultralytics YOLO11, you can follow these steps:
- ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ(
cv2
,ultralytics
). - ์นด์ดํ ์์ญ(์: ๋ค๊ฐํ, ์ ๋ฑ)์ ์ ์ํฉ๋๋ค.
- ๋์์ ์บก์ฒ๋ฅผ ์ค์ ํ๊ณ ๊ฐ์ฒด ์นด์ดํฐ๋ฅผ ์ด๊ธฐํํฉ๋๋ค.
- ๊ฐ ํ๋ ์์ ์ฒ๋ฆฌํ์ฌ ๊ฐ์ฒด๋ฅผ ์ถ์ ํ๊ณ ์ ์๋ ์์ญ ๋ด์์ ๊ฐ์ฒด๋ฅผ ๊ณ์ฐํฉ๋๋ค.
๋ค์์ ํ ์ง์ญ์์ ๊ณ์ฐํ๋ ๊ฐ๋จํ ์์ ๋๋ค:
import cv2
from ultralytics import solutions
def count_objects_in_region(video_path, output_video_path, model_path):
"""Count objects in a specific region within a video."""
cap = cv2.VideoCapture(video_path)
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))
video_writer = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
region_points = [(20, 400), (1080, 404), (1080, 360), (20, 360)]
counter = solutions.ObjectCounter(show=True, region=region_points, model=model_path)
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or video processing has been successfully completed.")
break
im0 = counter.count(im0)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
count_objects_in_region("path/to/video.mp4", "output_video.avi", "yolo11n.pt")
๊ฐ์ฒด ์ ๊ณ์ฐ ์น์ ์์ ๋ ๋ง์ ๊ตฌ์ฑ ๋ฐ ์ต์ ์ ์ดํด๋ณด์ธ์.
What are the advantages of using Ultralytics YOLO11 for object counting?
Using Ultralytics YOLO11 for object counting offers several advantages:
- ๋ฆฌ์์ค ์ต์ ํ: ์ ํํ ์นด์ดํธ๋ฅผ ์ ๊ณตํ์ฌ ํจ์จ์ ์ธ ๋ฆฌ์์ค ๊ด๋ฆฌ๋ฅผ ์ฉ์ดํ๊ฒ ํ๊ณ , ์ฌ๊ณ ๊ด๋ฆฌ์ ๊ฐ์ ์ฐ์ ์์ ๋ฆฌ์์ค ํ ๋น์ ์ต์ ํํ๋ ๋ฐ ๋์์ ์ค๋๋ค.
- ๋ณด์ ๊ฐํ: ์ํฐํฐ๋ฅผ ์ ํํ๊ฒ ์ถ์ ํ๊ณ ๊ณ์ฐํ์ฌ ๋ณด์ ๋ฐ ๊ฐ์๋ฅผ ๊ฐํํ์ฌ ์ ์ ์ ์ธ ์ํ ํ์ง๋ฅผ ์ง์ํฉ๋๋ค.
- ์ ๋ณด์ ๊ธฐ๋ฐํ ์์ฌ ๊ฒฐ์ : ๋ฆฌํ ์ผ, ํธ๋ํฝ ๊ด๋ฆฌ ๋ฑ์ ์์ญ์์ ์์ฌ ๊ฒฐ์ ์ ์ํ ๊ท์คํ ์ธ์ฌ์ดํธ๋ฅผ ์ ๊ณตํ์ฌ ํ๋ก์ธ์ค๋ฅผ ์ต์ ํํฉ๋๋ค.
์ค์ ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์ฝ๋ ์์ ๋ฅผ ๋ณด๋ ค๋ฉด ๊ฐ์ฒด ์นด์ดํ ์ ์ฅ์ ์น์ ์ ์ฐธ์กฐํ์ธ์.
How can I count specific classes of objects using Ultralytics YOLO11?
To count specific classes of objects using Ultralytics YOLO11, you need to specify the classes you are interested in during the tracking phase. Below is a Python example:
import cv2
from ultralytics import solutions
def count_specific_classes(video_path, output_video_path, model_path, classes_to_count):
"""Count specific classes of objects in a video."""
cap = cv2.VideoCapture(video_path)
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))
video_writer = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
line_points = [(20, 400), (1080, 400)]
counter = solutions.ObjectCounter(show=True, region=line_points, model=model_path, classes=classes_to_count)
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or video processing has been successfully completed.")
break
im0 = counter.count(im0)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
count_specific_classes("path/to/video.mp4", "output_specific_classes.avi", "yolo11n.pt", [0, 2])
์ด ์์ ์์๋ classes_to_count=[0, 2]
ํด๋์ค์ ๊ฐ์ฒด๋ฅผ ๊ณ์ฐํ๋ค๋ ์๋ฏธ์
๋๋ค. 0
๊ทธ๋ฆฌ๊ณ 2
(์: ์ฌ๋ ๋ฐ ์๋์ฐจ).
Why should I use YOLO11 over other object detection models for real-time applications?
Ultralytics YOLO11 provides several advantages over other object detection models like Faster R-CNN, SSD, and previous YOLO versions:
- Speed and Efficiency: YOLO11 offers real-time processing capabilities, making it ideal for applications requiring high-speed inference, such as surveillance and autonomous driving.
- Accuracy: It provides state-of-the-art accuracy for object detection and tracking tasks, reducing the number of false positives and improving overall system reliability.
- Ease of Integration: YOLO11 offers seamless integration with various platforms and devices, including mobile and edge devices, which is crucial for modern AI applications.
- ์ ์ฐ์ฑ: ํน์ ์ฌ์ฉ ์ฌ๋ก ์๊ตฌ ์ฌํญ์ ์ถฉ์กฑํ๋๋ก ๊ตฌ์ฑ ๊ฐ๋ฅํ ๋ชจ๋ธ์ ํตํด ๊ฐ์ฒด ๊ฐ์ง, ์ธ๋ถํ, ์ถ์ ๊ณผ ๊ฐ์ ๋ค์ํ ์์ ์ ์ง์ํฉ๋๋ค.
Check out Ultralytics YOLO11 Documentation for a deeper dive into its features and performance comparisons.
Can I use YOLO11 for advanced applications like crowd analysis and traffic management?
Yes, Ultralytics YOLO11 is perfectly suited for advanced applications like crowd analysis and traffic management due to its real-time detection capabilities, scalability, and integration flexibility. Its advanced features allow for high-accuracy object tracking, counting, and classification in dynamic environments. Example use cases include:
- ๊ตฐ์ค ๋ถ์: ๋๊ท๋ชจ ๋ชจ์์ ๋ชจ๋ํฐ๋งํ๊ณ ๊ด๋ฆฌํ์ฌ ์์ ์ ๋ณด์ฅํ๊ณ ๊ตฐ์ค์ ํ๋ฆ์ ์ต์ ํํฉ๋๋ค.
- ๊ตํต ๊ด๋ฆฌ: ์ฐจ๋์ ์ถ์ ๋ฐ ์ง๊ณํ๊ณ , ๊ตํต ํจํด์ ๋ถ์ํ๊ณ , ์ค์๊ฐ์ผ๋ก ๊ตํต ํผ์ก์ ๊ด๋ฆฌํ์ธ์.
For more information and implementation details, refer to the guide on Real World Applications of object counting with YOLO11.