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
相关推荐
plmm烟酒僧13 分钟前
Windows下QT调用MinGW编译的OpenCVAI小杨29 分钟前
【车道线检测】一、传统车道线检测:基于霍夫变换的车道线检测史诗级详细教程冷凝女子2 小时前
【QT】海康视频及openCv抓拍正脸接口撞南墙者3 小时前
OpenCV自学系列(1)——简介和GUI特征操作王哈哈^_^4 小时前
【数据集】【YOLO】【VOC】目标检测数据集,查找数据集,yolo目标检测算法详细实战训练步骤!柳鲲鹏4 小时前
OpenCV视频防抖源码及编译脚本jndingxin4 小时前
OpenCV视觉分析之目标跟踪(8)目标跟踪函数CamShift()使用咔叽布吉6 小时前
【论文阅读笔记】CamoFormer: Masked Separable Attention for Camouflaged Object Detection深度学习lover9 小时前
<项目代码>YOLOv8 苹果腐烂识别<目标检测>Eric.Lee202114 小时前
yolo v5 开源项目