์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

Ultralytics YOLOv8 ๐Ÿš€์„ ์‚ฌ์šฉํ•œ ๊ฐœ์ฒด ์ˆ˜ ๊ณ„์‚ฐ

์˜ค๋ธŒ์ ํŠธ ์นด์šดํŒ…์ด๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”?

๊ฐ์ฒด ์นด์šดํŒ… Ultralytics YOLOv8 ์„ ์‚ฌ์šฉํ•œ ๊ฐ์ฒด ์นด์šดํŒ…์€ ๋น„๋””์˜ค ๋ฐ ์นด๋ฉ”๋ผ ์ŠคํŠธ๋ฆผ์—์„œ ํŠน์ • ๊ฐ์ฒด๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์‹๋ณ„ํ•˜๊ณ  ์นด์šดํŒ…ํ•˜๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค. YOLOv8 ์€ ์ตœ์ฒจ๋‹จ ์•Œ๊ณ ๋ฆฌ์ฆ˜๊ณผ ๋”ฅ๋Ÿฌ๋‹ ๊ธฐ๋Šฅ ๋•๋ถ„์— ๊ตฐ์ค‘ ๋ถ„์„ ๋ฐ ๊ฐ์‹œ์™€ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์‹œ๋‚˜๋ฆฌ์˜ค์—์„œ ํšจ์œจ์ ์ด๊ณ  ์ •ํ™•ํ•œ ๊ฐ์ฒด ์นด์šดํŒ…์„ ์ œ๊ณตํ•˜์—ฌ ์‹ค์‹œ๊ฐ„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ํƒ์›”ํ•œ ์„ฑ๋Šฅ์„ ๋ฐœํœ˜ํ•ฉ๋‹ˆ๋‹ค.



Watch: ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐœ์ฒด ์ˆ˜ ๊ณ„์‚ฐ Ultralytics YOLOv8

์˜ค๋ธŒ์ ํŠธ ์นด์šดํŒ…์˜ ์žฅ์ ์€?

  • ๋ฆฌ์†Œ์Šค ์ตœ์ ํ™”: ๊ฐœ์ฒด ์นด์šดํŒ…์€ ์ •ํ™•ํ•œ ๊ฐœ์ˆ˜๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žฌ๊ณ  ๊ด€๋ฆฌ์™€ ๊ฐ™์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ฆฌ์†Œ์Šค ํ• ๋‹น์„ ์ตœ์ ํ™”ํ•˜์—ฌ ํšจ์œจ์ ์ธ ๋ฆฌ์†Œ์Šค ๊ด€๋ฆฌ๋ฅผ ์šฉ์ดํ•˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ณด์•ˆ ๊ฐ•ํ™”: ๊ฐœ์ฒด ์นด์šดํŒ…์€ ๊ฐœ์ฒด๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์ถ”์ ํ•˜๊ณ  ์„ธ์–ด ๋ณด์•ˆ๊ณผ ๊ฐ์‹œ๋ฅผ ๊ฐ•ํ™”ํ•˜์—ฌ ์„ ์ œ์ ์ธ ์œ„ํ˜‘ ํƒ์ง€๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • ์ •๋ณด์— ๊ธฐ๋ฐ˜ํ•œ ์˜์‚ฌ ๊ฒฐ์ •: ๊ฐ์ฒด ์นด์šดํŒ…์€ ์†Œ๋งค์—…, ๊ตํ†ต ๊ด€๋ฆฌ ๋ฐ ๊ธฐํƒ€ ๋‹ค์–‘ํ•œ ์˜์—ญ์—์„œ ์˜์‚ฌ ๊ฒฐ์ •์„ ๋‚ด๋ฆฌ๊ณ  ํ”„๋กœ์„ธ์Šค๋ฅผ ์ตœ์ ํ™”ํ•˜๋Š” ๋ฐ ์œ ์šฉํ•œ ์ธ์‚ฌ์ดํŠธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์‹ค์ œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

๋ฌผ๋ฅ˜ ์–‘์‹์—…
์ปจ๋ฒ ์ด์–ด ๋ฒจํŠธ ํŒจํ‚ท ๊ณ„์ˆ˜ ์‚ฌ์šฉ Ultralytics YOLOv8 ๋ฐ”๋‹ค์—์„œ ๋ฌผ๊ณ ๊ธฐ ์ˆ˜ ์„ธ๊ธฐ 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)

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)

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)

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 ํด๋ž˜์Šค ์ด๋ฆ„ ์‚ฌ์ „
region_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_thickness int 2 ๊ฐœ์ฒด ๋‘๊ป˜๋Š” ํ…์ŠคํŠธ๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
count_txt_color RGB Color (0, 0, 0) ๊ฐœ์ฒด ์นด์šดํŠธ ํ…์ŠคํŠธ์˜ ์ „๊ฒฝ์ƒ‰
count_color RGB Color (255, 255, 255) ๊ฐœ์ฒด ์นด์šดํŠธ ํ…์ŠคํŠธ์˜ ๋ฐฐ๊ฒฝ์ƒ‰
region_thickness int 5 ๊ฐœ์ฒด ์นด์šดํ„ฐ ์˜์—ญ ๋˜๋Š” ์„ ์˜ ๋‘๊ป˜

์ธ์ˆ˜ 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-03-03
์ž‘์„ฑ์ž: glenn-jocher (8), AyushExel (1), chr043416@gmail.com (3), RizwanMunawar (1)

๋Œ“๊ธ€