opencv-yolov8-目标检测

复制代码
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()
相关推荐
向哆哆4 小时前
常见鸟类物种识别数据集:生态监测与生物多样性保护的视觉资源
目标检测
向哆哆5 小时前
茶叶病害与健康状态检测数据集:精准农业与智能防控的茶叶病害数据
目标检测
挂科边缘15 小时前
YOLOv12环境配置,手把手教你使用YOLOv12训练自己的数据集和推理(附YOLOv12网络结构图),全文最详细教程
人工智能·深度学习·yolo·目标检测·计算机视觉·yolov12
咚咚王者19 小时前
人工智能之视觉领域 计算机视觉 第十章 图像直方图
人工智能·opencv·计算机视觉
向哆哆1 天前
白血病细胞与正常细胞识别数据集:医学影像与智能诊断的细胞分析数据
人工智能·目标检测·计算机视觉
youcans_1 天前
【跟我学YOLO】YOLO26(3)安装配置与快速使用
图像处理·yolo·目标检测·计算机视觉·环境配置
Katecat996631 天前
基于sparse-rcnn_r50_fpn的冰球目标检测与识别系统改进与部署
人工智能·目标检测·计算机视觉
jay神1 天前
基于深度学习的无人机航拍小目标检测算法研究
人工智能·深度学习·目标检测·计算机视觉·毕业设计
Coding茶水间2 天前
基于深度学习的番茄叶子病虫害监测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
图像处理·人工智能·python·深度学习·yolo·目标检测
麦麦大数据2 天前
F071_vue+flask基于YOLOv8的实时目标检测与追踪系统
vue.js·yolo·目标检测·flask·vue·视频检测