From a7326a41651001c9650812a00ed1eaa7271a064e Mon Sep 17 00:00:00 2001 From: wangcong Date: Tue, 15 Jun 2021 15:21:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=20=E4=BF=AE=E6=94=B9Tesseract=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=BA=93=E5=AE=9A=E4=B9=89=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 优化三方库不能在application后实例化 Log: 修改识别接口 Change-Id: Ia36d0b9c9e43fab1d1a637728f0dbabccff3679e --- src/tessocrutils/tessocrutils.cpp | 10 ++++++---- src/tessocrutils/tessocrutils.h | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tessocrutils/tessocrutils.cpp b/src/tessocrutils/tessocrutils.cpp index 44b9a2f..f7424e7 100644 --- a/src/tessocrutils/tessocrutils.cpp +++ b/src/tessocrutils/tessocrutils.cpp @@ -49,6 +49,12 @@ const QString TESSDATA_PATH = "/usr/share/deepin-ocr/tesslangs"; */ TessOcrUtils *TessOcrUtils::m_tessOcrUtils = nullptr; +/** + * @brief TessOcrUtils::t_Tesseract 三方库实例化 + */ +tesseract::TessBaseAPI *TessOcrUtils::t_Tesseract = new tesseract::TessBaseAPI(); + + TessOcrUtils::TessOcrUtils() { @@ -226,10 +232,7 @@ RecognitionResult TessOcrUtils::getRecogitionResult(Pix * image,ResultType resul setResult(errorCode,errorMessage,resultType,t_result); return t_result; } - tesseract::TessBaseAPI *t_Tesseract = new tesseract::TessBaseAPI(); try{ - //实例化tesseract - t_Tesseract = new tesseract::TessBaseAPI(); //初始化语言包 if (t_Tesseract->Init(m_sTessdataPath.toLatin1().data(), m_sLangs.toLatin1().data())) { @@ -267,7 +270,6 @@ RecognitionResult TessOcrUtils::getRecogitionResult(Pix * image,ResultType resul return t_result; } t_Tesseract->End(); - delete t_Tesseract; pixDestroy(&image); t_result.flag = true; t_result.message = errorMessage; diff --git a/src/tessocrutils/tessocrutils.h b/src/tessocrutils/tessocrutils.h index afdfdeb..a5372ff 100644 --- a/src/tessocrutils/tessocrutils.h +++ b/src/tessocrutils/tessocrutils.h @@ -244,6 +244,8 @@ private : static TessOcrUtils *m_tessOcrUtils; + static tesseract::TessBaseAPI *t_Tesseract; + }; #endif // TESSOCRUTILS_H