YOLOV8最简图像分类检测推理代码

安装YOLOV8

首先要去YOLOV8的官网安装库
YOLOV8官方网站

powershell 复制代码
# Install the ultralytics package from PyPI
pip install ultralytics

安装opencv

powershell 复制代码
pip install opencv-python
python 复制代码
import cv2
from ultralytics import YOLO

# Load the YOLOv8 model
model = YOLO('yolov8n.pt')

# Open the video file
video_path = 0
cap = cv2.VideoCapture(video_path)

# Loop through the video frames
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(1) & 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()

更短的

python 复制代码
import cv2
from ultralytics import YOLO

# Load the YOLOv8 model
model = YOLO('yolov8n.pt')

# Open the video file
video_path = 0
cap = cv2.VideoCapture(video_path)

# Loop through the video frames
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()

    if success:
        # Run YOLOv8 inference on the frame
        results = model(frame, show=True)

        # 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(1) & 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()
相关推荐
hans汉斯5 小时前
计算机科学与应用|基于大模型深度语义理解的智能内容纠错系统
人工智能·计算机视觉·视觉检测·数据·病虫害检测
探物 AI5 小时前
【感知·yolov11】零基础友好:大白话拆解 YOLOv11,像素变检测框底层逻辑一遍过
yolo
这张生成的图像能检测吗10 小时前
(论文速读)LogInsight:基于大语言模型的准确可解释日志故障诊断
人工智能·计算机视觉·语言模型·自然语言处理·故障诊断
前网易架构师-高司机10 小时前
带标注的升降杆识别数据集,识别率93.7%,3496张图,支持yolo,coco json,voc xml,文末有模型训练代码
yolo·数据集·高速·升降杆·抬杆··
广州灵眸科技有限公司12 小时前
瑞芯微(EASY EAI)RV1126B yolov11-track多目标跟踪部署教程
linux·开发语言·网络·人工智能·yolo·机器学习·目标跟踪
深度学习lover12 小时前
<数据集>yolo食物分类检测<目标检测>
人工智能·深度学习·yolo·目标检测·计算机视觉·食物分类识别
AI棒棒牛13 小时前
RT-DETR最新创新改进系列:2D轻量解码结构重塑检测颈部,减少下采样链路,降低计算冗余,让端到端检测更快更轻!【轻装上阵,实时优先】
人工智能·深度学习·目标检测·计算机视觉·rt-detr
数据法师13 小时前
Sora退场,GPT Image 2.0封神!免费不限次还支持中文!
人工智能·gpt·计算机视觉
乔江seven13 小时前
【跟李沐学AI】24 狗的品种识别(ImageNet Dogs)
人工智能·深度学习·计算机视觉·微调·imagenetdogs
硬件学长森哥15 小时前
Android影像基础-3A在系统平台中的实现
android·图像处理·计算机视觉