Ultralytics YOLOv8 ๐์ ์ฌ์ฉํ ์ธ์คํด์ค ์ธ๋ถํ ๋ฐ ์ถ์
์ธ์คํด์ค ์ธ๋ถํ๋ ๋ฌด์์ธ๊ฐ์?
Ultralytics YOLOv8 ์ธ์คํด์ค ๋ถํ ์ ์ด๋ฏธ์ง์์ ๊ฐ๋ณ ๊ฐ์ฒด๋ฅผ ์๋ณํ๊ณ ์ค๊ณฝ์ ๊ทธ๋ ค ๊ณต๊ฐ ๋ถํฌ์ ๋ํ ์์ธํ ์ดํด๋ฅผ ์ ๊ณตํฉ๋๋ค. ์๋งจํฑ ์ธ๋ถํ์๋ ๋ฌ๋ฆฌ ๊ฐ ๊ฐ์ฒด์ ๊ณ ์ ํ ๋ ์ด๋ธ์ ์ง์ ํ๊ณ ์ ํํ๊ฒ ๋ฌ์ฌํ๋ฏ๋ก ๊ฐ์ฒด ๊ฐ์ง ๋ฐ ์๋ฃ ์์๊ณผ ๊ฐ์ ์์ ์ ๋งค์ฐ ์ค์ํฉ๋๋ค.
Ultralytics ํจํค์ง์์ ์ฌ์ฉํ ์ ์๋ ์ธ์คํด์ค ์ธ๋ถํ ์ถ์ ์๋ ๋ ๊ฐ์ง ์ ํ์ด ์์ต๋๋ค:
-
ํด๋์ค ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ ์ธ์คํด์ค ์ธ๋ถํ: ๊ฐ ํด๋์ค ๊ฐ์ฒด์๋ ์๊ฐ์ ์ผ๋ก ๋ช ํํ๊ฒ ๊ตฌ๋ถํ ์ ์๋๋ก ๊ณ ์ ํ ์์์ด ํ ๋น๋ฉ๋๋ค.
-
์ค๋ธ์ ํธ ํธ๋์ ์ฌ์ฉํ ์ธ์คํด์ค ์ธ๋ถํ: ๋ชจ๋ ํธ๋์ ๊ณ ์ ํ ์์์ผ๋ก ํ์๋์ด ์ฝ๊ฒ ์๋ณํ๊ณ ์ถ์ ํ ์ ์์ต๋๋ค.
Watch: ์ค๋ธ์ ํธ ์ถ์ ์ ์ฌ์ฉํ ์ธ์คํด์ค ์ธ๋ถํ Ultralytics YOLOv8
์ํ
์ธ์คํด์ค ์ธ๋ถํ | ์ธ์คํด์ค ์ธ๋ถํ + ์ค๋ธ์ ํธ ์ถ์ |
---|---|
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 ์ด์ ์น์ ๋๋ ์๋์ ์ธ๊ธ๋ ํ ๋ก ์น์ ์ ์์ ๋กญ๊ฒ ์ง๋ฌธ์ ๊ฒ์ํด ์ฃผ์ธ์.