InferNetOnnxPaddleOcrDetect.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef __InferNetOnnxPaddleOcrDetectC_H__
  2. #define __InferNetOnnxPaddleOcrDetectC_H__
  3. #include <iostream>
  4. #include <opencv2/imgproc.hpp>
  5. #include <opencv2/highgui.hpp>
  6. #include <onnxruntime_cxx_api.h>
  7. #include <locale>
  8. #include <codecvt>
  9. #ifdef __ANDROID__
  10. #include <android/log.h>
  11. #endif
  12. #include "../TextBlock.h"
  13. using namespace cv;
  14. using namespace std;
  15. using namespace Ort;
  16. class InferNetOnnxPaddleOcrDetect
  17. {
  18. public:
  19. // 默认构造函数
  20. InferNetOnnxPaddleOcrDetect();
  21. void LoadNetwork(const void* modelData, size_t modelDataLength);
  22. /**
  23. * \brief 处理一张图
  24. * \param srcimg 输入的图像数据
  25. * \return
  26. */
  27. std::vector<TextBlock> Process(cv::Mat& srcimg);
  28. /**
  29. * \brief 推理结果提取box框
  30. * \param binaryIN 输入的结果二值化后图像数据
  31. * \param srcimgIN 输入的原始图像数据
  32. * \return
  33. */
  34. std::vector<TextBlock> GetTextBoxes(cv::Mat& binaryIN, cv::Mat& srcimgIN);
  35. /**
  36. * \brief 在原始图像绘制结果框
  37. * \param srcimg 输入的原始图像数据
  38. * \param results 输入的结果boxs
  39. * \return
  40. */
  41. void drawPred(Mat& srcimg, std::vector< std::vector<Point2f> > results);
  42. /**
  43. * \brief 该函数用于从原始图像中裁剪和旋转感兴趣区域(ROI)
  44. * \param frame
  45. * \param vertices
  46. **/
  47. Mat getRotateCropImage(Mat& frame, std::vector<Point2f> vertices);
  48. void Dispose();
  49. private:
  50. float polygonThreshold = 0.0f;
  51. float binaryThreshold = 0.0f;
  52. float boxScore;
  53. float unclipRatio = 0.0f;
  54. int maxCandidates = 0;
  55. int longSideThresh = 3;//minBox 长边门限
  56. int shortSize = 736;
  57. float meanValues[3] = { 0.485f, 0.456f, 0.406f };
  58. float normValues[3] = { 0.229f, 0.224f, 0.225f };
  59. float contourScore(Mat& binary, std::vector<Point>& contour);
  60. void unclip(std::vector<Point2f>& inPoly, std::vector<Point2f>& outPoly);
  61. std::vector< std::vector<Point2f> > order_points_clockwise(std::vector< std::vector<Point2f> > results);
  62. Mat preprocess(Mat srcimg);
  63. std::vector<float> input_image_;
  64. void normalize_(Mat img);
  65. Session* net;
  66. Env env = Env(ORT_LOGGING_LEVEL_ERROR, "DBNet");
  67. SessionOptions sessionOptions = SessionOptions();
  68. std::vector<char*> inputNames;
  69. std::vector<char*> outputNames;
  70. volatile bool _modelLoaded = false;
  71. Point2f pointCenBoxs(vector<Point2f> Boxs);
  72. };
  73. #endif