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()
相关推荐
jndingxin2 小时前
OpenCV视频I/O(14)创建和写入视频文件的类:VideoWriter介绍
人工智能·opencv·音视频
FL16238631295 小时前
[C++]使用纯opencv部署yolov11旋转框目标检测
opencv·yolo·目标检测
方世恩8 小时前
【进阶OpenCV】 (5)--指纹验证
人工智能·opencv·目标检测·计算机视觉
FL16238631298 小时前
[C++]使用纯opencv部署yolov11-pose姿态估计onnx模型
c++·opencv·yolo
A_lvvx8 小时前
OpenCV透视变换
人工智能·opencv·计算机视觉
鲸~屿9 小时前
计算机视觉 第十章OpenCV
人工智能·opencv·计算机视觉
Eric.Lee202110 小时前
数据集-目标检测系列- 螃蟹 检测数据集 crab >> DataBall
python·深度学习·算法·目标检测·计算机视觉·数据集·螃蟹检测
菜就多练_082813 小时前
《深度学习》OpenCV 摄像头OCR 过程及案例解析
人工智能·深度学习·opencv·ocr
给算法爸爸上香13 小时前
YOLOv11尝鲜测试五分钟极简配置
yolo·目标检测·yolov11
xuehaishijue14 小时前
红外画面空中目标检测系统源码分享
人工智能·目标检测·计算机视觉