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()
相关推荐
Coding茶水间15 小时前
基于深度学习的草莓健康度检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
图像处理·人工智能·深度学习·yolo·目标检测·机器学习·计算机视觉
老艾的AI世界1 天前
最新AI幻脸软件,全面升级可直播,Mirage下载介绍(支持cpu)
图像处理·人工智能·深度学习·神经网络·目标检测·ai
jghhh011 天前
基于阈值分割的车牌定位识别
图像处理·opencv·计算机视觉
AI即插即用1 天前
即插即用系列 | 2025 RestorMixer:融合 CNN、Mamba 与 Transformer 的高效图像复原的集大成者!
人工智能·深度学习·神经网络·目标检测·计算机视觉·cnn·transformer
阿_旭1 天前
Python中3类目标检测方法详解:从原理到实践
python·目标检测
夏天是冰红茶1 天前
小目标检测:PinwheelConv详解
人工智能·目标检测·计算机视觉
Coding茶水间2 天前
基于深度学习的螺栓螺母检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
图像处理·人工智能·深度学习·yolo·目标检测·机器学习·计算机视觉
AI小怪兽2 天前
RF-DETR:实时检测Transformer的神经架构搜索,首个突破 60 AP 的实时检测器 | ICLR 2026 in Submission
人工智能·深度学习·yolo·目标检测·架构·transformer
智驱力人工智能2 天前
从人海战术到智能巡逻 城市街道违规占道AI识别系统的实践与思考 占道经营检测系统价格 占道经营AI预警系统
人工智能·安全·yolo·目标检测·无人机·边缘计算
逻辑流浪者2 天前
推荐一个意外好用的图像标注平台(YOLOv8 项目实测)
yolo·目标检测·计算机视觉·图像标注