#pragma once #ifdef ORTTOOLKIT #define ORTTOOLKIT __declspec(dllexport) #else #define ORTTOOLKIT __declspec(dllimport) #endif #include #include #include #include #include "Type.h" namespace OrtToolkit { namespace Vision { namespace Detect { /// /// 飞桨PP_YOLOE转ONNX模型BatchSize只能为1 /// class ORTTOOLKIT PP_YOLOE { public: /// /// PP_YOLOE模型初始化 /// /// 模型路径 /// 置信度阈值 /// ONNX概念下的 执行提供程序 (EP),参数为字符串,默认为CPU,其他:CUDA PP_YOLOE(std::string model_path, float confThreshold, std::string ExecutionProvider = "CUDA"); /// /// 目标检测 /// /// 输入OpenCV的BGR图像 void Predict(cv::Mat& cv_image, Type::Res_PP_YOLOE& res); private: float confThreshold;//置信度阈值 cv::Mat preprocess(cv::Mat srcimg); const int inpWidth = 640; const int inpHeight = 640; std::vector mean_ = { 0.485, 0.456, 0.406 }; std::vector std_ = { 0.229, 0.224, 0.225 }; std::vector input_image_; std::vector scale_factor = { 1,1 }; Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "PP_YOLOE"); Ort::Session* ort_session = nullptr; Ort::SessionOptions sessionOptions = Ort::SessionOptions(); std::vector input_names; std::vector output_names; std::vector> input_node_dims; // 输入节点维度 std::vector> output_node_dims; // 输出节点维度 }; } namespace FaceDetect { class ORTTOOLKIT YOLOV7_face { public: YOLOV7_face(float confThreshold, float nmsThreshold, std::string modelpath, std::string ExecutionProvider = "CUDA"); void Predict(cv::Mat& frame, Type::Res_YOLOV7_FACE& generate_boxes); private: int inpWidth; int inpHeight; int nout; int num_proposal; float confThreshold;//置信度阈值 float nmsThreshold;//nms阈值 std::vector mean_ = { 0.5,0.5,0.5 }; std::vector std_ = { 0.5,0.5,0.5 }; std::vector input_image_;//模型输入图片 void nms(std::vectorItems, Type::Res_YOLOV7_FACE& Res);//NMS bool has_postprocess; std::vectorIn_AllocatedStringPtr; std::vectorOut_AllocatedStringPtr; Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "YOLOV7_face"); Ort::Session* ort_session = nullptr;//OnnxRunTime会话 Ort::SessionOptions sessionOptions = Ort::SessionOptions(); std::vector input_names; std::vector output_names; std::vector> input_node_dims; // >=1 outputs std::vector> output_node_dims; // >=1 outputs }; } namespace FaceAlign { class ORTTOOLKIT PFLD98 { public: PFLD98(std::string ModPath); void Predict(cv::Mat& Img, std::vector& Density); ~PFLD98(); private: Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_WARNING, "MCNN"); Ort::SessionOptions sessionOptions = Ort::SessionOptions(); Ort::AllocatorWithDefaultOptions allocator; const char* input_name; const char* output_nameA; const char* output_nameB; std::vector input_dims; std::vector output_dims; Ort::Session* ort_session; std::vector input_names; std::vector output_names; std::vector input_node_names; std::vector output_node_names; private: int DensityRow; int DensityCol; std::vector input_image_; }; } namespace FaceId { class ORTTOOLKIT Arcface { public: Arcface(std::string modelpath, std::string ExecutionProvider = "CUDA"); void Predict(cv::Mat& frame, std::vector& FaceVector); private: int inpWidth; int inpHeight; int nout; std::vector input_image_;//模型输入图片 std::vector mean_ = { 0.5, 0.5, 0.5 }; std::vector std_ = { 0.5, 0.5, 0.5 }; std::vectorIn_AllocatedStringPtr; std::vectorOut_AllocatedStringPtr; Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "Arcface");//日志记录 Ort::Session* ort_session = nullptr;//OnnxRunTime会话 Ort::SessionOptions sessionOptions = Ort::SessionOptions(); std::vector input_names; std::vector output_names; std::vector> input_node_dims; // >=1 outputs std::vector> output_node_dims; // >=1 outputs }; } namespace CrowdCounting { class ORTTOOLKIT MCNN { public: MCNN(std::string ModPath); void Predict(cv::Mat& Img, std::vector& Density); ~MCNN(); private: Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_WARNING, "MCNN"); Ort::SessionOptions sessionOptions = Ort::SessionOptions(); Ort::AllocatorWithDefaultOptions allocator; const char* input_name; const char* output_name; std::vector input_dims; std::vector output_dims; Ort::Session* ort_session; std::vector input_names; std::vector output_names; std::vector input_node_names; std::vector output_node_names; std::vector input_image_; private: int DensityRow; int DensityCol; }; } } namespace Util{ void ORTTOOLKIT overflow(float& info, int lower, int upper); void ORTTOOLKIT BoxOverflow(Type::Base_Type_Box& Box, int lower, int upper); float ORTTOOLKIT CosineSimilarity(const std::vector& a, const std::vector& b, bool normalized = false); std::string ORTTOOLKIT create_uuid(); uint16_t floatToHalf(float f); float halfToFloat(uint16_t h); template void ReadBin(U& x, std::string path) { std::ifstream file(path, std::ios::binary); if (file) { file.seekg(0, std::ios::end); std::streampos size = file.tellg(); file.seekg(0, std::ios::beg); x.resize(size / sizeof(T)); file.read(reinterpret_cast(x.data()), size); file.close(); } }; } }