使用Ultralytics YOLO11 🚀 进行 VisionEye 视图对象映射
什么是 VisionEye Object Mapping?
Ultralytics YOLO11VisionEye 可让计算机模拟人眼的观察精度,识别并精确定位物体。这一功能使计算机能够辨别并聚焦于特定物体,就像人眼从特定视角观察细节一样。
样品
VisionEye 视图 | 带有物体跟踪功能的 VisionEye 视图 | 带有距离计算功能的 VisionEye 视图 |
---|---|---|
使用 VisionEye 视图对象映射Ultralytics YOLO11 | 使用 VisionEye View 物体映射功能进行物体跟踪Ultralytics YOLO11 | 使用 VisionEye View 进行距离计算Ultralytics YOLO11 |
使用 VisionEye 物体映射YOLO11
import cv2
from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator, colors
model = YOLO("yolo11n.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 Annotator, colors
model = YOLO("yolo11n.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 math
import cv2
from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator
model = YOLO("yolo11n.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 精确定位色彩 |
备注
如有任何疑问,请随时在Ultralytics 问题板块或下面提到的讨论板块发布您的问题。
常见问题
如何通过Ultralytics YOLO11 开始使用 VisionEye Object Mapping?
要开始在Ultralytics YOLO11 上使用 VisionEye Object Mapping,首先需要通过 pip 安装Ultralytics YOLO 软件包。然后,您可以使用文档中提供的示例代码使用 VisionEye 设置对象检测。下面是一个简单的示例:
import cv2
from ultralytics import YOLO
model = YOLO("yolo11n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")
while True:
ret, frame = cap.read()
if not ret:
break
results = model.predict(frame)
for result in results:
# Perform custom logic with result
pass
cv2.imshow("visioneye", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
VisionEye 使用Ultralytics YOLO11 进行物体跟踪的主要功能是什么?
VisionEye 的物体跟踪功能(Ultralytics YOLO11 )可让用户跟踪视频帧内物体的移动。主要功能包括
- 实时物体跟踪:可在物体移动时对其进行跟踪。
- 物体识别:利用YOLO11 强大的检测算法。
- 距离计算计算物体与指定点之间的距离。
- 注释和可视化:为跟踪对象提供可视化标记。
下面是使用 VisionEye 进行跟踪的简短代码片段:
import cv2
from ultralytics import YOLO
model = YOLO("yolo11n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")
while True:
ret, frame = cap.read()
if not ret:
break
results = model.track(frame, persist=True)
for result in results:
# Annotate and visualize tracking
pass
cv2.imshow("visioneye-tracking", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
有关全面指南,请访问VisionEye Object Mapping with Object Tracking。
如何使用 VisionEye 的YOLO11 模型计算距离?
VisionEye 和Ultralytics YOLO11 的距离计算包括确定检测到的物体与帧中指定点的距离。它增强了空间分析能力,在自动驾驶和监控等应用中非常有用。
下面是一个简化的例子:
import math
import cv2
from ultralytics import YOLO
model = YOLO("yolo11n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")
center_point = (0, 480) # Example center point
pixel_per_meter = 10
while True:
ret, frame = cap.read()
if not ret:
break
results = model.track(frame, persist=True)
for result in results:
# Calculate distance logic
distances = [
(math.sqrt((box[0] - center_point[0]) ** 2 + (box[1] - center_point[1]) ** 2)) / pixel_per_meter
for box in results
]
cv2.imshow("visioneye-distance", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
有关详细说明,请参阅带有距离计算功能的 VisionEye。
为什么要使用Ultralytics YOLO11 进行对象映射和跟踪?
Ultralytics YOLO11 以速度快、精度高、易于集成而闻名,是对象映射和跟踪的首选。主要优势包括
- 最先进的性能:实时物体检测精度高。
- 灵活性:支持检测、跟踪和距离计算等各种任务。
- 社区和支持:丰富的文档和活跃的 GitHub 社区,可用于故障排除和改进。
- 易用性:直观的应用程序接口可简化复杂的任务,实现快速部署和迭代。
有关申请和福利的更多信息,请查阅Ultralytics YOLO11 文档。
如何将 VisionEye 与Comet 或ClearML 等其他机器学习工具集成?
Ultralytics YOLO11 可以与Comet 和ClearML 等各种机器学习工具无缝集成,增强了实验跟踪、协作和可重复性。请按照有关如何使用YOLOv5 与Comet以及将YOLO11 与ClearML 集成的详细指南开始操作。
如需进一步了解和了解集成示例,请查阅我们的Ultralytics 集成指南。