跳至内容

使用Ultralytics YOLOv8 🚀 进行 VisionEye 视图对象映射

什么是 VisionEye Object Mapping?

Ultralytics YOLOv8VisionEye 可模拟人眼的观察精度,为计算机提供识别和精确定位物体的能力。这一功能使计算机能够辨别并聚焦于特定物体,就像人眼从特定视角观察细节一样。

样品

VisionEye 视图 带有物体跟踪功能的 VisionEye 视图
使用 VisionEye 视图对象映射Ultralytics YOLOv8 使用 VisionEye View 对象映射和对象跟踪功能Ultralytics YOLOv8
使用 VisionEye 视图对象映射Ultralytics YOLOv8 使用 VisionEye View 对象映射和对象跟踪功能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()

visioneye 论据

名称 类型 默认值 说明
color tuple (235, 219, 11) 线条和对象中心点颜色
pin_color tuple (255, 0, 255) VisionEye 精确定位色彩
thickness int 2 精确到物体的线条粗细
pins_radius int 10 针尖和目标中心点圆半径

备注

如有任何疑问,请随时在Ultralytics 问题板块或下面提到的讨论板块发布您的问题。



创建于 2023-12-18,更新于 2024-01-15
作者:glenn-jocher(5)、chr043416@gmail.com(1)

评论