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()
相关推荐
pen-ai1 小时前
【YOLO系列】 YOLOv1 目标检测算法原理详解
算法·yolo·目标检测
格林威2 小时前
Baumer相机铆钉安装状态检测:判断铆接是否到位的 5 个核心算法,附 OpenCV+Halcon 的实战代码!
人工智能·opencv·算法·计算机视觉·视觉检测·工业相机·堡盟相机
李昊哲小课2 小时前
OpenCV Haar级联分类器人脸检测完整教程
人工智能·opencv·计算机视觉
格林威3 小时前
Baumer相机铸件气孔与缩松识别:提升铸造良品率的 6 个核心算法,附 OpenCV+Halcon 实战代码!
人工智能·opencv·算法·安全·计算机视觉·堡盟相机·baumer相机
光羽隹衡3 小时前
计算机视觉——Opencv(图像金字塔)
人工智能·opencv·计算机视觉
sali-tec3 小时前
C# 基于OpenCv的视觉工作流-章20-仿射变换
图像处理·人工智能·opencv·算法·计算机视觉
沃达德软件4 小时前
视频侦查图像清晰化技术
图像处理·人工智能·目标检测·机器学习·计算机视觉·视觉检测·超分辨率重建
工程师老罗4 小时前
目标检测的常见数据集
人工智能·目标检测·计算机视觉
子夜江寒5 小时前
基于dlib与OpenCV的人脸检测与特征点标定技术实践
人工智能·opencv·计算机视觉
IRevers5 小时前
RF-DETR:第一个在COCO上突破60AP的DETR(含检测和分割推理)
图像处理·人工智能·python·深度学习·目标检测·计算机视觉