From e91314a9d9b1fcc6c2f9793022af5d1e0f2669e3 Mon Sep 17 00:00:00 2001 From: hemingyang Date: Mon, 27 Dec 2021 17:35:50 +0800 Subject: [PATCH] =?UTF-8?q?chore(ocr):=20ocr=20=E5=86=85=E5=AD=98=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 内存泄露错误修改 Log: amd平台内存错误 Change-Id: Icc80b482ec645fd2c525c70e0d59c63c8e71d38f --- src/tessocrutils/tessocrutils.cpp | 6 ++++-- tests/tessocrutils/test_tessocrutils.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tessocrutils/tessocrutils.cpp b/src/tessocrutils/tessocrutils.cpp index ba4ee8d..81012f1 100644 --- a/src/tessocrutils/tessocrutils.cpp +++ b/src/tessocrutils/tessocrutils.cpp @@ -169,7 +169,9 @@ RecognitionResult TessOcrUtils::getRecogitionResult(QImage *image, const ResultT //p_image->colormap->depth; //p_image->colormap->nalloc; //p_image->colormap->n; - p_image->data = reinterpret_cast(image->bits()); + //p_image->data = reinterpret_cast(image->bits()); + //pixSetData(p_image, reinterpret_cast(image->bits())); + memcpy(reinterpret_cast(pixGetData(p_image)), reinterpret_cast(image->bits()), p_image->wpl * p_image->h * 4); //获取识别结果 return getRecognizeResult(p_image,resultType); } @@ -296,7 +298,7 @@ RecognitionResult TessOcrUtils::getRecognizeResult(Pix * image,ResultType result return t_result; } t_Tesseract->End(); - //pixDestroy(&image); + pixDestroy(&image); t_result.flag = true; t_result.message = errorMessage; t_result.errorCode = ErrorCode::OK; diff --git a/tests/tessocrutils/test_tessocrutils.cpp b/tests/tessocrutils/test_tessocrutils.cpp index fbad0b1..630d636 100644 --- a/tests/tessocrutils/test_tessocrutils.cpp +++ b/tests/tessocrutils/test_tessocrutils.cpp @@ -158,7 +158,8 @@ TEST_F(TessOcrUtilsTest, getRecognizeResult) p_image->special = 0; p_image->text = nullptr; p_image->colormap = nullptr; - p_image->data = reinterpret_cast(image->bits()); + //p_image->data = reinterpret_cast(image->bits()); + memcpy(reinterpret_cast(pixGetData(p_image)), reinterpret_cast(image->bits()), p_image->wpl * p_image->h * 4); RecognitionResult recognitionResult = call_private_fun::TessOcrUtilsgetRecognizeResult(*m_tessOCrUtils,p_image,resultType); EXPECT_EQ(true, recognitionResult.flag); EXPECT_EQ("", recognitionResult.message);