Ultralytics YOLOv8 ๐๋ฅผ ์ฌ์ฉํ VisionEye ๋ทฐ ์ค๋ธ์ ํธ ๋งคํ
๋น์ ์์ด ์ค๋ธ์ ํธ ๋งคํ์ด๋ ๋ฌด์์ธ๊ฐ์?
Ultralytics YOLOv8 VisionEye๋ ์ปดํจํฐ๊ฐ ๋ฌผ์ฒด๋ฅผ ์๋ณํ๊ณ ์ ํํ ์ฐพ์๋ผ ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ์ฌ ์ฌ๋์ ๋์ ๊ด์ฐฐ ์ ๋ฐ๋๋ฅผ ์๋ฎฌ๋ ์ด์ ํฉ๋๋ค. ์ด ๊ธฐ๋ฅ์ ํตํด ์ปดํจํฐ๋ ์ฌ๋์ ๋์ด ํน์ ์์ ์์ ์ธ๋ถ ์ฌํญ์ ๊ด์ฐฐํ๋ ๋ฐฉ์๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํน์ ๋ฌผ์ฒด๋ฅผ ์๋ณํ๊ณ ์ง์คํ ์ ์์ต๋๋ค.
์ํ
๋น์ ์์ด ๋ทฐ | ๊ฐ์ฒด ์ถ์ ๊ธฐ๋ฅ์ด ์๋ VisionEye ๋ทฐ | ๊ฑฐ๋ฆฌ ๊ณ์ฐ์ด ํฌํจ๋ VisionEye ๋ณด๊ธฐ |
---|---|---|
VisionEye ๋ทฐ ๊ฐ์ฒด ๋งคํ์ ์ฌ์ฉํ์ฌ Ultralytics YOLOv8 | ๋ค์์ ์ฌ์ฉํ์ฌ ๊ฐ์ฒด ์ถ์ ์ ํตํ VisionEye ๋ณด๊ธฐ ๊ฐ์ฒด ๋งคํ Ultralytics YOLOv8 | ๋ค์์ ์ฌ์ฉํ์ฌ ๊ฑฐ๋ฆฌ ๊ณ์ฐ์ด ํฌํจ๋ VisionEye ๋ณด๊ธฐ Ultralytics YOLOv8 |
VisionEye ์ค๋ธ์ ํธ ๋งคํ์ ์ฌ์ฉํ์ฌ YOLOv8
import cv2
from ultralytics import YOLO
from ultralytics.utils.plotting import colors, Annotator
model = YOLO("yolov8n.pt")
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('visioneye-pinpoint.avi', cv2.VideoWriter_fourcc(*'MJPG'), fps, (w, h))
center_point = (-10, 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)
boxes = results[0].boxes.xyxy.cpu()
clss = results[0].boxes.cls.cpu().tolist()
annotator = Annotator(im0, line_width=2)
for box, cls in zip(boxes, clss):
annotator.box_label(box, label=names[int(cls)], color=colors(int(cls)))
annotator.visioneye(box, center_point)
out.write(im0)
cv2.imshow("visioneye-pinpoint", 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 colors, Annotator
model = YOLO("yolov8n.pt")
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('visioneye-pinpoint.avi', cv2.VideoWriter_fourcc(*'MJPG'), fps, (w, h))
center_point = (-10, 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)
boxes = results[0].boxes.xyxy.cpu()
if results[0].boxes.id is not None:
track_ids = results[0].boxes.id.int().cpu().tolist()
for box, track_id in zip(boxes, track_ids):
annotator.box_label(box, label=str(track_id), color=colors(int(track_id)))
annotator.visioneye(box, center_point)
out.write(im0)
cv2.imshow("visioneye-pinpoint", im0)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
out.release()
cap.release()
cv2.destroyAllWindows()
import cv2
import math
from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator, colors
model = YOLO("yolov8s.pt")
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('visioneye-distance-calculation.avi', cv2.VideoWriter_fourcc(*'MJPG'), fps, (w, h))
center_point = (0, h)
pixel_per_meter = 10
txt_color, txt_background, bbox_clr = ((0, 0, 0), (255, 255, 255), (255, 0, 255))
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)
boxes = results[0].boxes.xyxy.cpu()
if results[0].boxes.id is not None:
track_ids = results[0].boxes.id.int().cpu().tolist()
for box, track_id in zip(boxes, track_ids):
annotator.box_label(box, label=str(track_id), color=bbox_clr)
annotator.visioneye(box, center_point)
x1, y1 = int((box[0] + box[2]) // 2), int((box[1] + box[3]) // 2) # Bounding box centroid
distance = (math.sqrt((x1 - center_point[0]) ** 2 + (y1 - center_point[1]) ** 2))/pixel_per_meter
text_size, _ = cv2.getTextSize(f"Distance: {distance:.2f} m", cv2.FONT_HERSHEY_SIMPLEX,1.2, 3)
cv2.rectangle(im0, (x1, y1 - text_size[1] - 10),(x1 + text_size[0] + 10, y1), txt_background, -1)
cv2.putText(im0, f"Distance: {distance:.2f} m",(x1, y1 - 5), cv2.FONT_HERSHEY_SIMPLEX, 1.2,txt_color, 3)
out.write(im0)
cv2.imshow("visioneye-distance-calculation", im0)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
out.release()
cap.release()
cv2.destroyAllWindows()
visioneye
์ธ์
์ด๋ฆ | ์ ํ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
---|---|---|---|
color |
tuple |
(235, 219, 11) |
์ ๋ฐ ๊ฐ์ฒด ์ค์ฌ์ |
pin_color |
tuple |
(255, 0, 255) |
VisionEye ํํฌ์ธํธ ์ปฌ๋ฌ |
thickness |
int |
2 |
์ค๋ธ์ ํธ ์ ๋๊ป์ ๋ํ ํํฌ์ธํธ |
pins_radius |
int |
10 |
ํ ํฌ์ธํธ ๋ฐ ๊ฐ์ฒด ์ค์ฌ์ ์ ๋ฐ๊ฒฝ |
์ฐธ๊ณ
๋ฌธ์ ์ฌํญ์ด ์์ผ์๋ฉด Ultralytics ์ด์ ์น์ ๋๋ ์๋์ ์ธ๊ธ๋ ํ ๋ก ์น์ ์ ์์ ๋กญ๊ฒ ์ง๋ฌธ์ ๊ฒ์ํด ์ฃผ์ธ์.