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

Ultralytics YOLOv8 ๐Ÿš€์„ ์‚ฌ์šฉํ•œ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ

๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ์ด๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”?

๋‘ ๋ฌผ์ฒด ์‚ฌ์ด์˜ ๊ฐ„๊ฒฉ์„ ์ธก์ •ํ•˜๋Š” ๊ฒƒ์„ ์ง€์ •๋œ ๊ณต๊ฐ„ ๋‚ด์—์„œ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์˜ ๊ฒฝ์šฐ Ultralytics YOLOv8์˜ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ•์กฐ ํ‘œ์‹œํ•œ ๊ฒฝ๊ณ„ ์ƒ์ž์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ„์‚ฐํ•˜๊ธฐ ์œ„ํ•ด ๊ฒฝ๊ณ„ ์ƒ์ž ์ค‘์‹ฌ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.



Watch: ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ Ultralytics YOLOv8

๋น„์ฃผ์–ผ

๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ Ultralytics YOLOv8
Ultralytics YOLOv8 ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ

๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ์˜ ์žฅ์ ์€?

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

YOLOv8 ์„ ์‚ฌ์šฉํ•œ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ ์˜ˆ์‹œ

import cv2

from ultralytics import YOLO, solutions

model = YOLO("yolov8n.pt")
names = model.model.names

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("distance_calculation.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

# Init distance-calculation obj
dist_obj = solutions.DistanceCalculation(names=names, view_img=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 = dist_obj.start_process(im0, tracks)
    video_writer.write(im0)

cap.release()
video_writer.release()
cv2.destroyAllWindows()
์ฐธ๊ณ 
  • ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ ํด๋ฆญํ•˜๋ฉด ๊ทธ๋ ค์ง„ ๋ชจ๋“  ์ ์ด ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.
  • ๋งˆ์šฐ์Šค ์™ผ์ชฝ ํด๋ฆญ์œผ๋กœ ์ ์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ธ์ˆ˜ DistanceCalculation()

Name Type Default ์„ค๋ช…
names dict None ํด๋ž˜์Šค ์ธ๋ฑ์Šค๋ฅผ ํด๋ž˜์Šค ์ด๋ฆ„์— ๋งคํ•‘ํ•˜๋Š” ์‚ฌ์ „.
pixels_per_meter int 10 ํ”ฝ์…€์—์„œ ๋ฏธํ„ฐ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ณ„์ˆ˜์ž…๋‹ˆ๋‹ค.
view_img bool False ๋น„๋””์˜ค ์ŠคํŠธ๋ฆผ์„ ํ‘œ์‹œํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ํ”Œ๋ž˜๊ทธ์ž…๋‹ˆ๋‹ค.
line_thickness int 2 ์ด๋ฏธ์ง€์— ๊ทธ๋ ค์ง„ ์„ ์˜ ๋‘๊ป˜์ž…๋‹ˆ๋‹ค.
line_color tuple (255, 255, 0) ์ด๋ฏธ์ง€์— ๊ทธ๋ ค์ง„ ์„ ์˜ ์ƒ‰์ƒ(BGR ํ˜•์‹).
centroid_color tuple (255, 0, 255) ๊ทธ๋ ค์ง„ ๊ตฌ์‹ฌ์ ์˜ ์ƒ‰์ƒ(BGR ํ˜•์‹).

์ธ์ˆ˜ 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 ๊ฐœ์ฒด ์ถ”์  ๊ฒฐ๊ณผ ํ‘œ์‹œ


Created 2024-01-05, Updated 2024-06-10
Authors: glenn-jocher (6), IvorZhu331 (1), RizwanMunawar (5), AyushExel (1)

๋Œ“๊ธ€