目錄
寫在前面
項目介紹
最新發布說明
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 parametersconst std::string labelsPath = "../models/coco.names"; // Path to class labelsconst std::string modelPath = "../models/yolo11n-seg.onnx"; // Path to YOLO11 modelconst std::string imagePath = "../data/dogs.jpg"; // Path to input imagebool isGPU = true; // Set to false for CPU processing// Initialize the YOLO11 segmentorYOLOv11SegDetector segmentor(modelPath, labelsPath, isGPU);// Load an imagecv::Mat image = cv::imread(imagePath);// Perform object segmentation to get segmentation masks and bboxsstd::vector<Segmentation> results = detector.segment(img, 0.2f, 0.45f);// Draw bounding boxes on the imagesegmentor.drawSegmentations(image, results); // Masks only// segmentor.drawSegmentationsAndBoxes(image, results); // Masks and Detections// Display the annotated imagecv::imshow("YOLO11 Segmentation and Detections", image);cv::waitKey(0); // Wait indefinitely until a key is pressedreturn 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