diff --git a/3rdPart/include/OcrLiteNcnn/OcrLite.h b/3rdPart/include/OcrLiteNcnn/OcrLite.h index a04d2b03ed..f1b721fac8 100644 --- a/3rdPart/include/OcrLiteNcnn/OcrLite.h +++ b/3rdPart/include/OcrLiteNcnn/OcrLite.h @@ -8,50 +8,68 @@ #include "CrnnNet.h" namespace ocr { - class OCRLITE_EXPORT OcrLite { - public: - OcrLite(); + class OCRLITE_EXPORT OcrLite { + public: + OcrLite(); - ~OcrLite(); + ~OcrLite(); - void setNumThread(int numOfThread); + void setNumThread(int numOfThread); - void initLogger(bool isConsole, bool isPartImg, bool isResultImg); + void initLogger(bool isConsole, bool isPartImg, bool isResultImg); - void enableResultTxt(const char* path, const char* imgName); + void enableResultTxt(const char* path, const char* imgName); - void setGpuIndex(int gpuIndex); + void setGpuIndex(int gpuIndex); - bool initModels(const std::string& detPath, const std::string& clsPath, - const std::string& recPath, const std::string& keysPath); + bool initModels(const std::string& detPath, const std::string& clsPath, + const std::string& recPath, const std::string& keysPath); - void Logger(const char* format, ...); + void Logger(const char* format, ...); - OcrResult detect(const char* path, const char* imgName, - int padding, int maxSideLen, - float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); + /* + * padding:图像预处理,在图片外周添加白边,用于提升识别率,文字框没有正确框住所有文字时,增加此值。 + * maxSideLen :按图片最长边的长度,此值为0代表不缩放,例:1024,如果图片长边大于1024则把图像整体缩小到1024再进行图像分割计算,如果图片长边小于1024则不缩放,如果图片长边小于32,则缩放到32。 + * boxScoreThresh:文字框置信度门限,文字框没有正确框住所有文字时,减小此值。 + * boxThresh:请自行试验。 + * unClipRatio:单个文字框大小倍率,越大时单个文字框越大。此项与图片的大小相关,越大的图片此值应该越大。 + * doAngle:启用(1)/禁用(0) 文字方向检测,只有图片倒置的情况下(旋转90~270度的图片),才需要启用文字方向检测。 + * mostAngle:启用(1)/禁用(0) 角度投票(整张图片以最大可能文字方向来识别),当禁用文字方向检测时,此项也不起作用。 + */ + OcrResult detect(const char* path, const char* imgName, + int padding, int maxSideLen, + float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); - OcrResult detect(const cv::Mat & mat, - int padding, int maxSideLen, - float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); - private: - bool isOutputConsole = false; - bool isOutputPartImg = false; - bool isOutputResultTxt = false; - bool isOutputResultImg = false; - FILE* resultTxt; - DbNet dbNet; - AngleNet angleNet; - CrnnNet crnnNet; + /* + * padding:图像预处理,在图片外周添加白边,用于提升识别率,文字框没有正确框住所有文字时,增加此值。 + * maxSideLen :按图片最长边的长度,此值为0代表不缩放,例:1024,如果图片长边大于1024则把图像整体缩小到1024再进行图像分割计算,如果图片长边小于1024则不缩放,如果图片长边小于32,则缩放到32。 + * boxScoreThresh:文字框置信度门限,文字框没有正确框住所有文字时,减小此值。 + * boxThresh:请自行试验。 + * unClipRatio:单个文字框大小倍率,越大时单个文字框越大。此项与图片的大小相关,越大的图片此值应该越大。 + * doAngle:启用(1)/禁用(0) 文字方向检测,只有图片倒置的情况下(旋转90~270度的图片),才需要启用文字方向检测。 + * mostAngle:启用(1)/禁用(0) 角度投票(整张图片以最大可能文字方向来识别),当禁用文字方向检测时,此项也不起作用。 + */ + OcrResult detect(const cv::Mat& mat, + int padding, int maxSideLen, + float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); + private: + bool isOutputConsole = false; + bool isOutputPartImg = false; + bool isOutputResultTxt = false; + bool isOutputResultImg = false; + FILE* resultTxt; + DbNet dbNet; + AngleNet angleNet; + CrnnNet crnnNet; - std::vector getPartImages(cv::Mat& src, std::vector& textBoxes, - const char* path, const char* imgName); + std::vector getPartImages(cv::Mat& src, std::vector& textBoxes, + const char* path, const char* imgName); - OcrResult detect(const char* path, const char* imgName, - cv::Mat& src, cv::Rect& originRect, ScaleParam& scale, - float boxScoreThresh = 0.6f, float boxThresh = 0.3f, - float unClipRatio = 2.0f, bool doAngle = true, bool mostAngle = true); - }; + OcrResult detect(const char* path, const char* imgName, + cv::Mat& src, cv::Rect& originRect, ScaleParam& scale, + float boxScoreThresh = 0.6f, float boxThresh = 0.3f, + float unClipRatio = 2.0f, bool doAngle = true, bool mostAngle = true); + }; } #endif //__OCR_LITE_H__ diff --git a/MeoAssistance/src/Identify.cpp b/MeoAssistance/src/Identify.cpp index 2e4ede5fd4..58836a602f 100644 --- a/MeoAssistance/src/Identify.cpp +++ b/MeoAssistance/src/Identify.cpp @@ -57,12 +57,12 @@ double Identify::image_hist_comp(const cv::Mat& src, const cv::MatND& hist) std::vector