123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #ifndef __InferNetOnnxPaddleOcrDetectC_H__
- #define __InferNetOnnxPaddleOcrDetectC_H__
- #include <iostream>
- #include <opencv2/imgproc.hpp>
- #include <opencv2/highgui.hpp>
- #include <onnxruntime_cxx_api.h>
- #include <locale>
- #include <codecvt>
- #ifdef __ANDROID__
- #include <android/log.h>
- #endif
- #include "../TextBlock.h"
- using namespace cv;
- using namespace std;
- using namespace Ort;
- class InferNetOnnxPaddleOcrDetect
- {
- public:
- // 默认构造函数
- InferNetOnnxPaddleOcrDetect();
- void LoadNetwork(const void* modelData, size_t modelDataLength);
- /**
- * \brief 处理一张图
- * \param srcimg 输入的图像数据
- * \return
- */
- std::vector<TextBlock> Process(cv::Mat& srcimg);
- /**
- * \brief 推理结果提取box框
- * \param binaryIN 输入的结果二值化后图像数据
- * \param srcimgIN 输入的原始图像数据
- * \return
- */
- std::vector<TextBlock> GetTextBoxes(cv::Mat& binaryIN, cv::Mat& srcimgIN);
- /**
- * \brief 在原始图像绘制结果框
- * \param srcimg 输入的原始图像数据
- * \param results 输入的结果boxs
- * \return
- */
- void drawPred(Mat& srcimg, std::vector< std::vector<Point2f> > results);
- /**
- * \brief 该函数用于从原始图像中裁剪和旋转感兴趣区域(ROI)
- * \param frame
- * \param vertices
- **/
- Mat getRotateCropImage(Mat& frame, std::vector<Point2f> vertices);
- void Dispose();
- private:
- float polygonThreshold = 0.0f;
- float binaryThreshold = 0.0f;
- float boxScore;
- float unclipRatio = 0.0f;
- int maxCandidates = 0;
- int longSideThresh = 3;//minBox 长边门限
- int shortSize = 736;
- float meanValues[3] = { 0.485f, 0.456f, 0.406f };
- float normValues[3] = { 0.229f, 0.224f, 0.225f };
- float contourScore(Mat& binary, std::vector<Point>& contour);
- void unclip(std::vector<Point2f>& inPoly, std::vector<Point2f>& outPoly);
- std::vector< std::vector<Point2f> > order_points_clockwise(std::vector< std::vector<Point2f> > results);
- Mat preprocess(Mat srcimg);
- std::vector<float> input_image_;
- void normalize_(Mat img);
- Session* net;
- Env env = Env(ORT_LOGGING_LEVEL_ERROR, "DBNet");
- SessionOptions sessionOptions = SessionOptions();
- std::vector<char*> inputNames;
- std::vector<char*> outputNames;
- volatile bool _modelLoaded = false;
- Point2f pointCenBoxs(vector<Point2f> Boxs);
- };
- #endif
|