// OnnxRuntimeInference.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#pragma once
#include <iostream>
#include <assert.h>
#include <vector>
#include <onnxruntime_cxx_api.h>
#include <string>
#include <opencv2/opencv.hpp>
#include "postProcess.h"
using namespace std;
using namespace cv;
using namespace postProcess;
void preDataDet(cv::Mat& matSrc, int& model_width, int& model_height, cv::Mat& matDst)
{
cv::cvtColor(matSrc, matDst, cv::COLOR_BGR2RGB);
cv::resize(matDst, matDst, cv::Size(model_width, model_height));
matDst.convertTo(matDst, CV_32FC3);
matDst = matDst / 255.0f;
}
int main()
{
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "ONNX_DETECTION"); //设置图优化类型
Ort::SessionOptions session_options;
session_options.SetIntraOpNumThreads(1);
session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_BASIC);
#ifdef _WIN32
const wchar_t* model_path = L"/OnnxRuntimeInference/weights/yolov5_model/best.onnx";
#else
const char* model_path = "/OnnxRuntimeInference/weights/yolov5_model/best.onnx";
#endif
Ort::Session session(env, model_path, session_options); // 创建会话,把模型加载到内存中 CPU
// print model input layer (node names, types, shape etc.)
Ort::AllocatorWithDefaultOptions allocator;
size_t num_input_nodes = session.GetInputCount();
size_t numInputNodes = session.GetInputCount(); //输入输出节点数量
size_t numOutputNodes = session.GetOutputCount();
vector<char*> input_names; // 定义一个字符指针vector
vector<char*> output_names; // 定义一个字符指针vector
vector<vector<int64_t>> input_node_dims; // >=1 outputs ,二维vector
vector<vector<int64_t>> output_node_dims; // >=1 outputs ,int64_t C/C++标准
for (int i = 0; i < numInputNodes; i
基于OnnxRuntime在C++端部署YOLOV5
最新推荐文章于 2025-01-22 10:14:11 发布