chore(ocr): ocr 内存错误

Description: 内存泄露错误修改

Log: amd平台内存错误
Change-Id: Icc80b482ec645fd2c525c70e0d59c63c8e71d38f
This commit is contained in:
hemingyang 2021-12-27 17:35:50 +08:00
parent 3ed93d0480
commit e91314a9d9
2 changed files with 6 additions and 3 deletions

View File

@ -169,7 +169,9 @@ RecognitionResult TessOcrUtils::getRecogitionResult(QImage *image, const ResultT
//p_image->colormap->depth; //p_image->colormap->depth;
//p_image->colormap->nalloc; //p_image->colormap->nalloc;
//p_image->colormap->n; //p_image->colormap->n;
p_image->data = reinterpret_cast<l_uint32*>(image->bits()); //p_image->data = reinterpret_cast<l_uint32*>(image->bits());
//pixSetData(p_image, reinterpret_cast<l_uint32*>(image->bits()));
memcpy(reinterpret_cast<void*>(pixGetData(p_image)), reinterpret_cast<void*>(image->bits()), p_image->wpl * p_image->h * 4);
//获取识别结果 //获取识别结果
return getRecognizeResult(p_image,resultType); return getRecognizeResult(p_image,resultType);
} }
@ -296,7 +298,7 @@ RecognitionResult TessOcrUtils::getRecognizeResult(Pix * image,ResultType result
return t_result; return t_result;
} }
t_Tesseract->End(); t_Tesseract->End();
//pixDestroy(&image); pixDestroy(&image);
t_result.flag = true; t_result.flag = true;
t_result.message = errorMessage; t_result.message = errorMessage;
t_result.errorCode = ErrorCode::OK; t_result.errorCode = ErrorCode::OK;

View File

@ -158,7 +158,8 @@ TEST_F(TessOcrUtilsTest, getRecognizeResult)
p_image->special = 0; p_image->special = 0;
p_image->text = nullptr; p_image->text = nullptr;
p_image->colormap = nullptr; p_image->colormap = nullptr;
p_image->data = reinterpret_cast<l_uint32*>(image->bits()); //p_image->data = reinterpret_cast<l_uint32*>(image->bits());
memcpy(reinterpret_cast<void*>(pixGetData(p_image)), reinterpret_cast<void*>(image->bits()), p_image->wpl * p_image->h * 4);
RecognitionResult recognitionResult = call_private_fun::TessOcrUtilsgetRecognizeResult(*m_tessOCrUtils,p_image,resultType); RecognitionResult recognitionResult = call_private_fun::TessOcrUtilsgetRecognizeResult(*m_tessOCrUtils,p_image,resultType);
EXPECT_EQ(true, recognitionResult.flag); EXPECT_EQ(true, recognitionResult.flag);
EXPECT_EQ("", recognitionResult.message); EXPECT_EQ("", recognitionResult.message);