基于OnnxRuntime在C++端部署YOLOV5

// 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值