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

Ultralytics YOLOv8 ๐Ÿš€์„ ์‚ฌ์šฉํ•œ ๊ฐœ์ฒด ์ž๋ฅด๊ธฐ

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

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

์˜ค๋ธŒ์ ํŠธ ์ž๋ฅด๊ธฐ์˜ ์žฅ์ ์€?

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

๋น„์ฃผ์–ผ

๊ณตํ•ญ ์ˆ˜ํ•˜๋ฌผ
๊ณตํ•ญ ์ปจ๋ฒ ์ด์–ด ๋ฒจํŠธ๋ฅผ ์ด์šฉํ•œ ์—ฌํ–‰ ๊ฐ€๋ฐฉ ์ž๋ฅด๊ธฐ Ultralytics YOLOv8
๊ณตํ•ญ ์ปจ๋ฒ ์ด์–ด ๋ฒจํŠธ๋ฅผ ์ด์šฉํ•œ ์—ฌํ–‰ ๊ฐ€๋ฐฉ ์ž๋ฅด๊ธฐ Ultralytics YOLOv8

YOLOv8 ๋ฅผ ์‚ฌ์šฉํ•œ ๊ฐœ์ฒด ์ž๋ฅด๊ธฐ ์˜ˆ์‹œ

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

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))

crop_dir_name = "ultralytics_crop"
if not os.path.exists(crop_dir_name):
    os.mkdir(crop_dir_name)

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

idx = 0
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):
            idx += 1
            annotator.box_label(box, color=colors(int(cls), True), label=names[int(cls)])

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

            cv2.imwrite(os.path.join(crop_dir_name, str(idx)+".png"), crop_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 ์‹คํ–‰ํ•  ๋””๋ฐ”์ด์Šค(์˜ˆ: ์ฟ ๋‹ค ๋””๋ฐ”์ด์Šค=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 ์ฃผ์–ด์ง„ ๋ ˆ์ด์–ด์—์„œ ํ”ผ์ฒ˜ ๋ฒกํ„ฐ/์ž„๋ฒ ๋”ฉ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.


์ƒ์„ฑ 2024-01-09, ์—…๋ฐ์ดํŠธ 2024-03-03
์ž‘์„ฑ์ž: glenn-jocher (2), chr043416@gmail.com (2), AyushExel (1)

๋Œ“๊ธ€