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

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

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

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



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

๋น„์ฃผ์–ผ

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

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

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

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

from ultralytics import YOLO
from ultralytics.solutions import distance_calculation
import cv2

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 = distance_calculation.DistanceCalculation()
dist_obj.set_args(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()
์ฐธ๊ณ 
  • ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ๊ทธ๋ ค์ง„ ๋ชจ๋“  ์ ์ด ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.
  • ๋งˆ์šฐ์Šค ์™ผ์ชฝ ํด๋ฆญ์œผ๋กœ ์ ์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„ ํƒ์  ์ธ์ˆ˜ set_args

์ด๋ฆ„ ์œ ํ˜• ๊ธฐ๋ณธ๊ฐ’ ์„ค๋ช…
names dict None ํด๋ž˜์Šค ์ด๋ฆ„
view_img bool False ์นด์šดํŠธ๊ฐ€ ์žˆ๋Š” ํ”„๋ ˆ์ž„ ํ‘œ์‹œ
line_thickness int 2 ๊ฒฝ๊ณ„ ์ƒ์ž ๋‘๊ป˜ ๋Š˜๋ฆฌ๊ธฐ
line_color RGB (255, 255, 0) ๋‘ ๊ฐœ์˜ ๊ฒฝ๊ณ„ ์ƒ์ž์— ๋งคํ•‘๋˜๋Š” ๊ตฌ์‹ฌ์ ์˜ ์„  ์ƒ‰์ƒ
centroid_color RGB (255, 0, 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 ๊ฐœ์ฒด ์ถ”์  ๊ฒฐ๊ณผ ํ‘œ์‹œ


์ƒ์„ฑ 2024-01-05, ์—…๋ฐ์ดํŠธ 2024-03-01
์ž‘์„ฑ์ž: chr043416@gmail.com (5), ๊ธ€๋ Œ-์กฐ์ฒ˜ (2), ์•„์œ ์‹œ์—‘์…€ (1)

๋Œ“๊ธ€