Ultralytics YOLOv8 ๐๋ฅผ ์ฌ์ฉํ ๊ฐ์ฒด ์ ๊ณ์ฐ
์ค๋ธ์ ํธ ์นด์ดํ ์ด๋ ๋ฌด์์ธ๊ฐ์?
๊ฐ์ฒด ์นด์ดํ Ultralytics YOLOv8 ๋ ๋์์ ๋ฐ ์นด๋ฉ๋ผ ์คํธ๋ฆผ์์ ํน์ ๊ฐ์ฒด๋ฅผ ์ ํํ๊ฒ ์๋ณํ๊ณ ์นด์ดํ ํ๋ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค. YOLOv8 ๋ ์ต์ฒจ๋จ ์๊ณ ๋ฆฌ์ฆ๊ณผ ๋ฅ๋ฌ๋ ๊ธฐ๋ฅ์ ํตํด ๊ตฐ์ค ๋ถ์ ๋ฐ ๊ฐ์์ ๊ฐ์ ๋ค์ํ ์๋๋ฆฌ์ค์์ ํจ์จ์ ์ด๊ณ ์ ํํ ๊ฐ์ฒด ์นด์ดํ ์ ์ ๊ณตํ๋ ์ค์๊ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ํ์ํ ์ฑ๋ฅ์ ๋ฐํํฉ๋๋ค.
Watch: ๋ค์์ ์ฌ์ฉํ์ฌ ๊ฐ์ฒด ์ ๊ณ์ฐ Ultralytics YOLOv8
์ค๋ธ์ ํธ ์นด์ดํ ์ ์ฅ์ ์?
- ๋ฆฌ์์ค ์ต์ ํ: ๊ฐ์ฒด ์นด์ดํ ์ ์ ํํ ๊ฐ์๋ฅผ ์ ๊ณตํ๊ณ ์ฌ๊ณ ๊ด๋ฆฌ์ ๊ฐ์ ์ ํ๋ฆฌ์ผ์ด์ ์์ ๋ฆฌ์์ค ํ ๋น์ ์ต์ ํํ์ฌ ํจ์จ์ ์ธ ๋ฆฌ์์ค ๊ด๋ฆฌ๋ฅผ ์ฉ์ดํ๊ฒ ํฉ๋๋ค.
- ๋ณด์ ๊ฐํ: ๊ฐ์ฒด ์นด์ดํ ์ ๊ฐ์ฒด๋ฅผ ์ ํํ๊ฒ ์ถ์ ํ๊ณ ๊ณ์ฐํ์ฌ ์ฌ์ ์ํ ํ์ง๋ฅผ ์ง์ํจ์ผ๋ก์จ ๋ณด์๊ณผ ๊ฐ์๋ฅผ ๊ฐํํฉ๋๋ค.
- ์ ๋ณด์ ๊ธฐ๋ฐํ ์์ฌ ๊ฒฐ์ : ๊ฐ์ฒด ์นด์ดํ ์ ์์ฌ ๊ฒฐ์ , ์๋งค์ , ๊ตํต ๊ด๋ฆฌ ๋ฐ ๊ธฐํ ๋ค์ํ ์์ญ์ ํ๋ก์ธ์ค ์ต์ ํ๋ฅผ ์ํ ๊ท์คํ ์ธ์ฌ์ดํธ๋ฅผ ์ ๊ณตํฉ๋๋ค.
์ค์ ์ ํ๋ฆฌ์ผ์ด์
๋ฌผ๋ฅ | ์์์ |
---|---|
์ปจ๋ฒ ์ด์ด ๋ฒจํธ ํจํท ๊ณ์ ์ฌ์ฉ Ultralytics YOLOv8 | ๋ฐ๋ค์์ ๋ฌผ๊ณ ๊ธฐ ์ ์ธ๊ธฐ Ultralytics YOLOv8 |
YOLOv8 ์์ ๋ฅผ ์ฌ์ฉํ ๊ฐ์ฒด ์ ๊ณ์ฐ
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
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 = object_counter.ObjectCounter()
counter.set_args(view_img=True,
reg_pts=region_points,
classes_names=model.names,
draw_tracks=True,
line_thickness=2)
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()
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,
line_thickness=2)
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()
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 line 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 = object_counter.ObjectCounter()
counter.set_args(view_img=True,
reg_pts=line_points,
classes_names=model.names,
draw_tracks=True,
line_thickness=2)
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()
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))
line_points = [(20, 400), (1080, 400)] # line or region points
classes_to_count = [0, 2] # person and car classes for count
# 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=line_points,
classes_names=model.names,
draw_tracks=True,
line_thickness=2)
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,
classes=classes_to_count)
im0 = counter.start_counting(im0, tracks)
video_writer.write(im0)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
์ง์ญ ์ด๋ ๊ฐ๋ฅ
ํ๋ ์์ ๊ฐ์ฅ์๋ฆฌ๋ฅผ ํด๋ฆญํ์ฌ ์์ญ์ ์ํ๋ ๊ณณ์ผ๋ก ์ด๋ํ ์ ์์ต๋๋ค.
์ ํ์ ์ธ์ set_args
์ด๋ฆ | ์ ํ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
---|---|---|---|
view_img |
bool |
False |
์นด์ดํธ๊ฐ ์๋ ํ๋ ์ ํ์ |
view_in_counts |
bool |
True |
๋น๋์ค ํ๋ ์์๋ง ์ธ์นด์ดํธ ํ์ |
view_out_counts |
bool |
True |
๋น๋์ค ํ๋ ์์๋ง ์์ ์นด์ดํธ ํ์ |
line_thickness |
int |
2 |
๊ฒฝ๊ณ ์์ ๋๋ฆฌ๊ธฐ ๋ฐ ํ ์คํธ ๋๊ป ๊ณ์ฐ |
reg_pts |
list |
[(20, 400), (1260, 400)] |
์ง์ญ์ ์ ์ํ๋ ํฌ์ธํธ ์์ญ |
classes_names |
dict |
model.model.names |
ํด๋์ค ์ด๋ฆ ์ฌ์ |
count_reg_color |
RGB Color |
(255, 0, 255) |
๊ฐ์ฒด ๊ณ์ฐ ์์ญ ๋๋ ์ ์ ์์ |
track_thickness |
int |
2 |
ํธ๋ํน ๋ผ์ธ์ ๋๊ป |
draw_tracks |
bool |
False |
ํธ๋ ๋ผ์ธ ๊ทธ๋ฆฌ๊ธฐ ํ์ฑํ |
track_color |
RGB Color |
(0, 255, 0) |
๊ฐ ํธ๋ ๋ผ์ธ์ ์์ |
line_dist_thresh |
int |
15 |
๋ผ์ธ ์นด์ดํฐ์ ์ ํด๋ฆฌ๋ ๊ฑฐ๋ฆฌ ์๊ณ๊ฐ |
count_txt_color |
RGB Color |
(255, 255, 255) |
๊ฐ์ฒด ์ ํ ์คํธ์ ์ ๊ฒฝ์ |
region_thickness |
int |
5 |
๊ฐ์ฒด ์นด์ดํฐ ์์ญ ๋๋ ์ ์ ๋๊ป |
count_bg_color |
RGB Color |
(255, 255, 255) |
ํ๊ดํ ์์ ๊ณ์ฐ |
์ธ์ model.track
์ด๋ฆ | ์ ํ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
---|---|---|---|
source |
im0 |
None |
์ด๋ฏธ์ง ๋๋ ๋น๋์ค์ ์์ค ๋๋ ํ ๋ฆฌ |
persist |
bool |
False |
ํ๋ ์ ๊ฐ ํธ๋ ์ง์ |
tracker |
str |
botsort.yaml |
์ถ์ ๋ฐฉ๋ฒ '๋ฐ์ดํธํธ๋' ๋๋ '๋ด์ํธ' |
conf |
float |
0.3 |
์ ๋ขฐ ์๊ณ๊ฐ |
iou |
float |
0.5 |
IOU ์๊ณ๊ฐ |
classes |
list |
None |
ํด๋์ค๋ณ๋ก ๊ฒฐ๊ณผ๋ฅผ ํํฐ๋งํฉ๋๋ค(์: classes=0 ๋๋ classes=[0,2,3]). |
verbose |
bool |
True |
๊ฐ์ฒด ์ถ์ ๊ฒฐ๊ณผ ํ์ |
์์ฑ 2023-12-02, ์ ๋ฐ์ดํธ 2024-04-18
์์ฑ์: glenn-jocher (9), RizwanMunawar (1), AyushExel (1)