YOLOv5Detector.h 1011 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <opencv2/opencv.hpp>
  5. #include <onnxruntime_cxx_api.h>
  6. #include <vector>
  7. #include <string>
  8. #include<QImage>
  9. using cv::Mat;
  10. using std::cout;
  11. using std::endl;
  12. using std::string;
  13. using std::vector;
  14. class YOLOv5Detector
  15. {
  16. public:
  17. YOLOv5Detector(const wchar_t* model_path);
  18. vector<vector<float>> detect(const cv::Mat& img);
  19. void draw_boxes(Mat& img, const vector<vector<float>>& info);
  20. cv::Mat QImageToMat(const QImage& image);
  21. private:
  22. Ort::Env env;
  23. Ort::MemoryInfo memory_info;
  24. Ort::SessionOptions session_options;
  25. Ort::Session session;
  26. bool use_cuda = false;
  27. const char* input_names[1] = { "images" }; // 根据模型的输入名调整
  28. const char* output_names[1] = { "output" }; // 根据模型的输出名调整
  29. static vector<vector<float>> get_info(const float* pdata, int total);
  30. static void info_simplify(vector<vector<float>>& info);
  31. static void nms(vector<vector<float>>& info);
  32. };