赞
踩
本篇主要介绍yolov8检测和分割模型利用OnnxRuntime进行部署。
yolov8链接:YOLOV8
部署环境:VS2017
配置环境:OpenCV、OnnxRuntime
-OpenCV:采用版本4.5.0以上,配置过程不多说了,网上搜搜吧。
-OnnxRuntime安装:采用工具-Nuget包管理器 进行安装
部分代码如下:
- #include <onnxruntime_cxx_api.h>
- #include <opencv2/opencv.hpp>
- #include <fstream>
- #include<random>
-
- using namespace cv;
- using namespace std;
-
- std::vector<std::string> labels;//全局变量
-
- std::vector<std::string> readClassNames(std::string file=std::string(""));
- bool DemoImg();
- bool predictImg(const std::string file);
- bool predictVid(const std::string file, const std::string modelfile = "yolov8n-seg.onnx");
- std::vector<cv::Scalar> colorInit(int n);
- float sigmoid(float x) {
- return 1 / (1 + exp(-x));
- }
- bool draw_masks(cv::Mat& inImg, cv::Mat& outImg, std::vector<int>& indexes,std::vector<cv::Rect>& boxes, std::vector<int>& classIds, std::vector<cv::Mat>& mask_maps, float mask_alpha=0.6);
-
- int main(int argc, char** argv) {
-
- 1. OpenCV测试
- //Mat img = imread("a.jpg");
- //cv::imshow("a.jpg", img);
- //waitKey(0);
- //DemoImg();
- //predictImg("b.jpg");
- predictVid("0", "yolov8n-seg.onnx");//"0""
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack.png)
完整代码:(70条消息) C++OnnxRuntime部署yolov8模型资源-CSDN文库
实验结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。