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

Ultralytics YOLOv8 ๐Ÿš€์„ ์‚ฌ์šฉํ•œ ์˜ค๋ธŒ์ ํŠธ ๋ธ”๋Ÿฌ๋ง

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

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



Watch: Object Blurring using Ultralytics YOLOv8

์˜ค๋ธŒ์ ํŠธ ๋ธ”๋Ÿฌ์˜ ์žฅ์ ์€?

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

YOLOv8 ์„ ์‚ฌ์šฉํ•œ ์˜ค๋ธŒ์ ํŠธ ํ๋ฆผ ์˜ˆ์ œ

import cv2

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

model = YOLO("yolov8n.pt")
names = 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))

# Blur ratio
blur_ratio = 50

# Video writer
video_writer = cv2.VideoWriter("object_blurring_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

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

    results = model.predict(im0, show=False)
    boxes = results[0].boxes.xyxy.cpu().tolist()
    clss = results[0].boxes.cls.cpu().tolist()
    annotator = Annotator(im0, line_width=2, example=names)

    if boxes is not None:
        for box, cls in zip(boxes, clss):
            annotator.box_label(box, color=colors(int(cls), True), label=names[int(cls)])

            obj = im0[int(box[1]) : int(box[3]), int(box[0]) : int(box[2])]
            blur_obj = cv2.blur(obj, (blur_ratio, blur_ratio))

            im0[int(box[1]) : int(box[3]), int(box[0]) : int(box[2])] = blur_obj

    cv2.imshow("ultralytics", im0)
    video_writer.write(im0)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
video_writer.release()
cv2.destroyAllWindows()

์ธ์ˆ˜ model.predict

์ด๋ฆ„ ์œ ํ˜• ๊ธฐ๋ณธ๊ฐ’ ์„ค๋ช…
source str 'ultralytics/assets' ์ด๋ฏธ์ง€ ๋˜๋Š” ๋น„๋””์˜ค์˜ ์†Œ์Šค ๋””๋ ‰ํ† ๋ฆฌ
conf float 0.25 ํƒ์ง€๋ฅผ ์œ„ํ•œ ๊ฐ์ฒด ์‹ ๋ขฐ ์ž„๊ณ„๊ฐ’
iou float 0.7 NMS์— ๋Œ€ํ•œ ๊ต์ฐจ์  ์˜ค๋ฒ„ ์œ ๋‹ˆ์˜จ(IoU) ์ž„๊ณ„๊ฐ’
imgsz int or tuple 640 ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ์Šค์นผ๋ผ ๋˜๋Š” (h, w) ๋ชฉ๋ก(์˜ˆ: (640, 480))์œผ๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
half bool False ๋ฐ˜์ •๋ฐ€๋„ ์‚ฌ์šฉ(FP16)
device None or str None ์‹คํ–‰ํ•  ๋””๋ฐ”์ด์Šค(์˜ˆ: CUDA ๋””๋ฐ”์ด์Šค=0/1/2/3 ๋˜๋Š” ๋””๋ฐ”์ด์Šค=CPU)
max_det int 300 ์ด๋ฏธ์ง€๋‹น ์ตœ๋Œ€ ํƒ์ง€ ํšŸ์ˆ˜
vid_stride bool False ๋น„๋””์˜ค ํ”„๋ ˆ์ž„ ์†๋„ ๋ณดํญ
stream_buffer bool False ๋ชจ๋“  ์ŠคํŠธ๋ฆฌ๋ฐ ํ”„๋ ˆ์ž„์„ ๋ฒ„ํผ๋งํ•˜๊ฑฐ๋‚˜(True) ๊ฐ€์žฅ ์ตœ๊ทผ ํ”„๋ ˆ์ž„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(False).
visualize bool False ๋ชจ๋ธ ๊ธฐ๋Šฅ ์‹œ๊ฐํ™”
augment bool False ์˜ˆ์ธก ์†Œ์Šค์— ์ด๋ฏธ์ง€ ์ฆ๊ฐ• ์ ์šฉ
agnostic_nms bool False ํด๋ž˜์Šค์— ๊ตฌ์• ๋ฐ›์ง€ ์•Š๋Š” NMS
classes list[int] None ํด๋ž˜์Šค๋ณ„๋กœ ๊ฒฐ๊ณผ๋ฅผ ํ•„ํ„ฐ๋งํ•ฉ๋‹ˆ๋‹ค(์˜ˆ: classes=0 ๋˜๋Š” classes=[0,2,3]).
retina_masks bool False ๊ณ ํ•ด์ƒ๋„ ์„ธ๋ถ„ํ™” ๋งˆ์Šคํฌ ์‚ฌ์šฉ
embed list[int] None ์ฃผ์–ด์ง„ ๋ ˆ์ด์–ด์—์„œ ํ”ผ์ฒ˜ ๋ฒกํ„ฐ/์ž„๋ฒ ๋”ฉ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.


Created 2024-01-09, Updated 2024-06-13
Authors: RizwanMunawar (1), glenn-jocher (5), IvorZhu331 (1), AyushExel (1)

๋Œ“๊ธ€