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()
相关推荐
菜狗woc6 小时前
opencv-python的简单练习
人工智能·python·opencv
西猫雷婶8 小时前
python学opencv|读取图像(十四)BGR图像和HSV图像通道拆分
开发语言·python·opencv
云空9 小时前
《QT 5.14.1 搭建 opencv 环境全攻略》
开发语言·qt·opencv
编码小哥9 小时前
opencv中的色彩空间
opencv·计算机视觉
吃个糖糖9 小时前
34 Opencv 自定义角点检测
人工智能·opencv·计算机视觉
花花少年9 小时前
【Windows版】opencv 和opencv_contrib配置
opencv·opencv_contrib
YRr YRr9 小时前
解决Ubuntu 20.04上编译OpenCV 3.2时遇到的stdlib.h缺失错误
linux·opencv·ubuntu
KeepThinking!9 小时前
YOLO-World:Real-Time Open-Vocabulary Object Detection
人工智能·yolo·目标检测·多模态
葡萄爱11 小时前
OpenCV图像分割
人工智能·opencv·计算机视觉
编码小哥13 小时前
通过opencv加载、保存视频
人工智能·opencv