import cv2
from ultralytics import YOLO
# 模型加载权重
model = YOLO('yolov8n.pt')
# 视频路径
cap = cv2.VideoCapture(0)
# 对视频中检测到目标画框标出来
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 inference on the frame
results = model(frame)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Inference", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(5) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()
opencv-yolov8-目标检测
W_en丶2023-08-19 10:51
相关推荐
菜狗woc6 小时前
opencv-python的简单练习西猫雷婶8 小时前
python学opencv|读取图像(十四)BGR图像和HSV图像通道拆分云空9 小时前
《QT 5.14.1 搭建 opencv 环境全攻略》编码小哥9 小时前
opencv中的色彩空间吃个糖糖9 小时前
34 Opencv 自定义角点检测花花少年9 小时前
【Windows版】opencv 和opencv_contrib配置YRr YRr9 小时前
解决Ubuntu 20.04上编译OpenCV 3.2时遇到的stdlib.h缺失错误KeepThinking!9 小时前
YOLO-World:Real-Time Open-Vocabulary Object Detection葡萄爱11 小时前
OpenCV图像分割编码小哥13 小时前
通过opencv加载、保存视频