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()
相关推荐
SDUERPANG4 小时前
三维目标检测|Iou3D 代码解读一
人工智能·目标检测·3d
视觉人机器视觉8 小时前
Visual Studio2022和C++opencv的配置保姆级教程
c++·opencv·visual studio
PyAIExplorer8 小时前
图像旋转:从原理到 OpenCV 实践
人工智能·opencv·计算机视觉
whoarethenext20 小时前
使用 C++/OpenCV 和 MFCC 构建双重认证智能门禁系统
开发语言·c++·opencv·mfcc
jndingxin20 小时前
OpenCV CUDA模块设备层-----高效地计算两个 uint 类型值的带权重平均值
人工智能·opencv·计算机视觉
晨同学032721 小时前
opencv的颜色通道问题 & rgb & bgr
人工智能·opencv·计算机视觉
看到我,请让我去学习1 天前
OpenCV开发-初始概念
人工智能·opencv·计算机视觉
PyAIExplorer1 天前
基于 OpenCV 的图像 ROI 切割实现
人工智能·opencv·计算机视觉
Ailerx2 天前
YOLOv13震撼发布:超图增强引领目标检测新纪元
人工智能·yolo·目标检测
阿蒙Amon2 天前
【Python小工具】使用 OpenCV 获取视频时长的详细指南
python·opencv·音视频