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

Ultralytics YOLOv8 ๐Ÿš€์„ ์‚ฌ์šฉํ•œ ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™” ๋ฐ ์ถ”์ 

์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™”๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”?

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

Ultralytics ํŒจํ‚ค์ง€์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™” ์ถ”์ ์—๋Š” ๋‘ ๊ฐ€์ง€ ์œ ํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค:

  • ํด๋ž˜์Šค ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•œ ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™”: ๊ฐ ํด๋ž˜์Šค ๊ฐ์ฒด์—๋Š” ์‹œ๊ฐ์ ์œผ๋กœ ๋ช…ํ™•ํ•˜๊ฒŒ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ณ ์œ ํ•œ ์ƒ‰์ƒ์ด ํ• ๋‹น๋ฉ๋‹ˆ๋‹ค.

  • ์˜ค๋ธŒ์ ํŠธ ํŠธ๋ž™์„ ์‚ฌ์šฉํ•œ ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™”: ๋ชจ๋“  ํŠธ๋ž™์€ ๊ณ ์œ ํ•œ ์ƒ‰์ƒ์œผ๋กœ ํ‘œ์‹œ๋˜์–ด ์‰ฝ๊ฒŒ ์‹๋ณ„ํ•˜๊ณ  ์ถ”์ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ƒ˜ํ”Œ

์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™” ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™” + ๊ฐœ์ฒด ์ถ”์ 
Ultralytics ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™” Ultralytics ์˜ค๋ธŒ์ ํŠธ ์ถ”์ ์„ ํ†ตํ•œ ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™”
Ultralytics ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™” ๐Ÿ˜ Ultralytics ์˜ค๋ธŒ์ ํŠธ ์ถ”์ ์„ ํ†ตํ•œ ์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™” ๐Ÿ”ฅ

์ธ์Šคํ„ด์Šค ์„ธ๋ถ„ํ™” ๋ฐ ์ถ”์ 

import cv2
from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator, colors

model = YOLO("yolov8n-seg.pt")  # segmentation model
names = model.model.names
cap = cv2.VideoCapture("path/to/video/file.mp4")
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter('instance-segmentation.avi', cv2.VideoWriter_fourcc(*'MJPG'), fps, (w, h))

while True:
    ret, im0 = cap.read()
    if not ret:
        print("Video frame is empty or video processing has been successfully completed.")
        break

    results = model.predict(im0)
    annotator = Annotator(im0, line_width=2)

    if results[0].masks is not None:
        clss = results[0].boxes.cls.cpu().tolist()
        masks = results[0].masks.xy
        for mask, cls in zip(masks, clss):
            annotator.seg_bbox(mask=mask,
                               mask_color=colors(int(cls), True),
                               det_label=names[int(cls)])

    out.write(im0)
    cv2.imshow("instance-segmentation", im0)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

out.release()
cap.release()
cv2.destroyAllWindows()
import cv2
from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator, colors

from collections import defaultdict

track_history = defaultdict(lambda: [])

model = YOLO("yolov8n-seg.pt")   # segmentation model
cap = cv2.VideoCapture("path/to/video/file.mp4")
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter('instance-segmentation-object-tracking.avi', cv2.VideoWriter_fourcc(*'MJPG'), fps, (w, h))

while True:
    ret, im0 = cap.read()
    if not ret:
        print("Video frame is empty or video processing has been successfully completed.")
        break

    annotator = Annotator(im0, line_width=2)

    results = model.track(im0, persist=True)

    if results[0].boxes.id is not None and results[0].masks is not None:
        masks = results[0].masks.xy
        track_ids = results[0].boxes.id.int().cpu().tolist()

        for mask, track_id in zip(masks, track_ids):
            annotator.seg_bbox(mask=mask,
                               mask_color=colors(track_id, True),
                               track_label=str(track_id))

    out.write(im0)
    cv2.imshow("instance-segmentation-object-tracking", im0)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

out.release()
cap.release()
cv2.destroyAllWindows()

seg_bbox ์ธ์ˆ˜

์ด๋ฆ„ ์œ ํ˜• ๊ธฐ๋ณธ๊ฐ’ ์„ค๋ช…
mask array None ์„ธ๋ถ„ํ™” ๋งˆ์Šคํฌ ์ขŒํ‘œ
mask_color tuple (255, 0, 255) ๋ชจ๋“  ์„ธ๋ถ„ํ™”๋œ ์ƒ์ž์˜ ๋งˆ์Šคํฌ ์ƒ‰์ƒ
det_label str None ์„ธ๋ถ„ํ™”๋œ ๊ฐœ์ฒด์— ๋Œ€ํ•œ ๋ ˆ์ด๋ธ”
track_label str None ์„ธ๋ถ„ํ™” ๋ฐ ์ถ”์ ๋œ ๊ฐœ์ฒด์— ๋Œ€ํ•œ ๋ ˆ์ด๋ธ”

์ฐธ๊ณ 

๋ฌธ์˜ ์‚ฌํ•ญ์ด ์žˆ์œผ์‹œ๋ฉด Ultralytics ์ด์Šˆ ์„น์…˜ ๋˜๋Š” ์•„๋ž˜์— ์–ธ๊ธ‰๋œ ํ† ๋ก  ์„น์…˜์— ์ž์œ ๋กญ๊ฒŒ ์งˆ๋ฌธ์„ ๊ฒŒ์‹œํ•˜์„ธ์š”.



์ƒ์„ฑ๋จ 2023-12-18, ์—…๋ฐ์ดํŠธ๋จ 2024-01-15
์ž‘์„ฑ์ž: glenn-jocher (5), chr043416@gmail.com (1)

๋Œ“๊ธ€