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);