【git-hub项目:YOLOs-CPP】本地实现01:项目构建

发布于:2025-02-14 ⋅ 阅读:(81) ⋅ 点赞:(0)

目录

写在前面

项目介绍

最新发布说明

Segmentation示例

功能特点

依赖项

安装

克隆代码仓库

配置

构建项目



写在前面

前面刚刚实现的系列文章:
【Windows/C++/yolo开发部署01】
【Windows/C++/yolo开发部署02】
【Windows/C++/yolo开发部署03】
【Windows/C++/yolo开发部署04】
【Windows/C++/yolo开发部署05】

必须用nividia显卡的电脑,才能运行最终生成的exe。但是,我想只用cpu实现实例分割,怎么办呢?我们今天来尝试这个项目:

Geekgineer/YOLOs-CPP

项目介绍

YOLOs-CPP 提供了单一的 C++ 头文件,具有高性能的应用程序,旨在使用来自 Ultralytics 的各种 YOLO(You Only Look Once)模型进行实时目标检测和分割。借助 ONNX Runtime 和 OpenCV 的强大功能,该项目为图像、视频和实时摄像头推理提供了无缝集成的统一 YOLOv(5,7,8,10,11) 实现。无论您是为研究、生产还是爱好者项目开发,该应用程序都提供了灵活性和高效性。

最新发布说明

[2025.01.26] 🔥🔥🔥 YOLOS-CPP 现在提供 YOLOv8 和 YOLOv11 的分割头文件,以及量化模型。

[2024.10.23] 🚀🚀🚀 YOLOS-CPP 项目启动,支持检测头文件。

Segmentation示例


// Include necessary headers
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

// Include the YOLOv11 Segmentation header
#include "YOLO11Seg.hpp"

int main()
{
    // Configuration parameters
    const std::string labelsPath = "../models/coco.names";       // Path to class labels
    const std::string modelPath  = "../models/yolo11n-seg.onnx";     // Path to YOLO11 model
    const std::string imagePath  = "../data/dogs.jpg";           // Path to input image
    bool isGPU = true;                                           // Set to false for CPU processing

    // Initialize the YOLO11 segmentor
    YOLOv11SegDetector segmentor(modelPath, labelsPath, isGPU);

    // Load an image
    cv::Mat image = cv::imread(imagePath);

    // Perform object segmentation to get segmentation masks and bboxs
    std::vector<Segmentation> results = detector.segment(img, 0.2f, 0.45f);

    // Draw bounding boxes on the image
    segmentor.drawSegmentations(image, results);          // Masks only
    // segmentor.drawSegmentationsAndBoxes(image, results); // Masks and Detections

    // Display the annotated image
    cv::imshow("YOLO11 Segmentation and Detections", image);
    cv::waitKey(0); // Wait indefinitely until a key is pressed

    return 0;
}

注意:有关更多用法,请查看以下源文件:image_inference.cpp

功能特点

  • 多种 YOLO 模型支持:支持 YOLOv5、YOLOv7、YOLOv8、YOLOv10 和 YOLOv11,包括标准和量化后的 ONNX 模型,以满足不同应用场景的需求。

  • ONNX Runtime 集成:利用 ONNX Runtime 在 CPU 和 GPU 上进行优化推理,确保高性能。

  • 动态形状处理:能够自动适应不同的输入尺寸,从而提高通用性。

  • 图优化:通过使用 ORT_ENABLE_ALL 进行模型优化来提升性能。

  • 执行提供者:配置会话以支持 CPU 或 GPU(例如,使用 CUDAExecutionProvider 支持 GPU)。

  • 输入/输出形状管理:根据模型规范管理动态输入张量形状。

  • 优化的内存分配:利用 Ort::MemoryInfo 在张量创建期间进行高效的内存管理。

  • 批处理:支持处理多张图像,目前主要关注单图像输入。

  • 输出张量提取:动态提取输出张量,以便灵活处理结果。

  • OpenCV 集成:使用 OpenCV 进行图像处理以及绘制边界框和标签(注意:不使用 cv::dnn 模块)。

  • 实时推理:能够即时处理图像、视频和实时摄像头数据。

  • 高效的检测处理:采用非极大值抑制(NMS)进行有效处理(注意:某些模型不使用 NMS,例如 YOLOv10)。

  • 跨平台支持:完全兼容 Linux、macOS 和 Windows 环境。

  • 易于使用的脚本:包含用于简单构建和运行不同推理模式的 shell 脚本。

依赖项

在构建项目之前,请确保您的系统已安装以下依赖项:

  • C++ 编译器:兼容 C++14 标准(例如,g++、clang++ 或 MSVC)。

  • CMake:3.0.0 或更高版本。

  • OpenCV:4.5.5 或更高版本。

  • ONNX Runti


网站公告

今日签到

点亮在社区的每一天
去签到