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()
相关推荐
劈星斩月2 小时前
OpenCV 学习3 - 裁剪图像
opencv·裁剪图像
大佬,救命!!!3 小时前
C++本地配置OpenCV
开发语言·c++·opencv·学习笔记·环境配置
Mrliu__4 小时前
Opencv(十八) : 图像凸包检测
人工智能·opencv·计算机视觉
小肖爱笑不爱笑5 小时前
LSDSSMs: 基于低秩稀疏分解状态空间模型的红外小目标检测网络(2025, TGRS)
人工智能·目标检测·计算机视觉
研华嵌入式5 小时前
用Edge Impulse开启你的边缘AI之旅
arm开发·图像处理·嵌入式硬件·目标检测·视觉检测·边缘计算
研华嵌入式5 小时前
从零到边缘:在AOM-2721 OSM开发套件上构建基于Edge Impulse的优化物体检测方案
arm开发·目标检测·计算机视觉·视觉检测
sponge'6 小时前
opencv学习笔记12:GAN网络
笔记·opencv·学习
南极星10056 小时前
OPENCV(python)--初学之路(十二)霍夫线/圆变换
人工智能·opencv·计算机视觉
AndrewHZ7 小时前
【图像处理基石】如何用OpenCV入门计算机视觉?
图像处理·深度学习·opencv·算法·计算机视觉·机器视觉·cv
社会零时工17 小时前
NVIDIA Jetson开发板使用记录——开发环境搭建
qt·opencv·nvidia