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()
相关推荐
乐迪信息1 小时前
乐迪信息:目标检测算法+AI摄像机:煤矿全场景识别方案
人工智能·物联网·算法·目标检测·目标跟踪·语音识别
学习3人组13 小时前
主流深度学习目标检测模型性能对比表
人工智能·深度学习·目标检测
学习3人组15 小时前
目标检测模型选型+训练调参极简步骤清单
人工智能·目标检测·决策树
Techblog of HaoWANG15 小时前
目标检测与跟踪 (7)- YOLOv8 ONNX量化模型部署指南
yolo·目标检测·onnx·量化部署
奔袭的算法工程师17 小时前
论文解读--FocalFormer3D : Focusing on Hard Instance for 3D Object Detection
人工智能·目标检测·计算机视觉
only-lucky17 小时前
OpenCV(第一章)
人工智能·opencv·计算机视觉
AndrewHZ20 小时前
【图像处理基石】如何高质量地生成一张庆祝元旦的图片?
图像处理·人工智能·opencv·算法·计算机视觉·生成式模型·genai
柠檬071120 小时前
vector<cv::point2f>如何快速转成opencv mat
人工智能·opencv·计算机视觉
Pyeako20 小时前
Opencv计算机视觉
人工智能·python·深度学习·opencv·计算机视觉
学习3人组20 小时前
目标检测训练常见问题排查清单
人工智能·目标检测·计算机视觉