Hello,
if you are really interesting in help/involving others for testing you need
to make it as simple as possible. E.g. providing most simple example.
I started to look on this one night, but need to stop cause I do no have
much time. So here I was I was able to do:
*1. get the test data ;-)*
wget https://cdn.cnn.com/cnn/2019/images/04/18/mueller-report.pdf
mkdir mueller
pdfimages mueller-report.pdf -all mueller\report
*2. make a simple testing code*
- I started on windows with clang (9 with msvc compatibility), which is
my most used setting at these day. testing case is in attachment
(test_tesseract.cpp)
- I limit loop to 15 pages.
- I found out that code did not run ocr correctly (while tesseract
executable has no problem with it ;-) ) so I need to add detection for page
rotation from leptonica.
- Anyway I saw there was crash after some processing some page (If I
remember correctly it crash on api->Clear()). Because I am not familiar wit
debugging on windows, I decided to run on linux. And ups c++17 code does
not worked... I than I wast time with using different compiler, looking for
other versions... and finally rewrite problematic part of code :-( And I
need to stopped at this point. At lease I was able to run this code on
linux for first 15 pages and it did not crash...
Just based on this it seems there is some problem on windows, because there
should not be crash.
Zdenko
ne 23. 6. 2019 o 16:20 _ Flaviu <[email protected]> napísal(a):
> No one noticed this fact ? If you read several images with tesseract, how
> is your RAM ?
>
> On Friday, June 21, 2019 at 4:37:02 PM UTC+3, zdenop wrote:
>>
>> yes - otherwise you will see memoryleak message when you app will
>> finish...ä
>> Zdenko
>>
>>
>> pi 21. 6. 2019 o 10:28 _ Flaviu <[email protected]> napísal(a):
>>
>>> As far I understand,
>>>
>>> pTess->End();
>>> is called on destructor, am I right ?
>>>
>>> On Thursday, June 20, 2019 at 2:42:49 PM UTC+3, zdenop wrote:
>>>>
>>>> IMO you have to call END() to correctly close tesseract instance.
>>>>
>>>> Zdenko
>>>>
>>>>
>>>> št 20. 6. 2019 o 13:02 _ Flaviu <[email protected]> napísal(a):
>>>>
>>>>> I am using tesseract 4 on a VC++ (MFC) app, to read text from images
>>>>> (A4 sizes). I noticed that while I using this app on several PCs (Win10 64
>>>>> bit, *GB RAM), the RAM occupied by my app (that use tesseract) is
>>>>> increasing on and on. If I read 14 images, my app eat 470 MB, and if I
>>>>> didn't close the app and read again all these 14 images, the RAM eaten by
>>>>> my app is increasing until ~800MB, and if continue to read the same
>>>>> images,
>>>>> the RAM is increasing on an on. Why is this happen ?
>>>>>
>>>>> Here is the code that I am using for tesseract:
>>>>>
>>>>> BOOL CMyClass::GetTextFromImage()
>>>>> {
>>>>> PIX* pix = NULL;
>>>>> tesseract::TessBaseAPI* pTess = new tesseract::TessBaseAPI;
>>>>>
>>>>> do
>>>>> {
>>>>> if (pTess->Init(...))
>>>>> {
>>>>> m_sError.Format(_T("OCRTesseract: Could not initialize tesseract."));
>>>>> break;
>>>>> }
>>>>> // setup
>>>>> // read image
>>>>> PIX* pix = pixRead(m_sFileName);
>>>>> if (! pix)
>>>>> {
>>>>> break;
>>>>> }
>>>>> // recognize
>>>>> pTess->SetImage(pix);
>>>>> }
>>>>> while (FALSE);
>>>>>
>>>>> // cleanup
>>>>> // pTess->Clear();
>>>>> // pTess->End();
>>>>> delete pTess;
>>>>> pTess = NULL;
>>>>> pixDestroy(&pix);
>>>>>
>>>>> return TRUE;
>>>>> }
>>>>>
>>>>>
>>>>> Is there anything wrong here ? Why is increasing RAM while I am using
>>>>> tesseract ?
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "tesseract-ocr" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at https://groups.google.com/group/tesseract-ocr.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/tesseract-ocr/8be010ab-c948-47d3-b51e-ac141ce12bbd%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/tesseract-ocr/8be010ab-c948-47d3-b51e-ac141ce12bbd%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "tesseract-ocr" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/tesseract-ocr.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/tesseract-ocr/125c6502-4afa-4fe6-ae04-f2ef14c0815b%40googlegroups.com
>>> <https://groups.google.com/d/msgid/tesseract-ocr/125c6502-4afa-4fe6-ae04-f2ef14c0815b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "tesseract-ocr" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/tesseract-ocr.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/tesseract-ocr/e1a32685-d11a-4860-ac92-533dd795375c%40googlegroups.com
> <https://groups.google.com/d/msgid/tesseract-ocr/e1a32685-d11a-4860-ac92-533dd795375c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tesseract-ocr/CAJbzG8xSOXpdvWPNTuGGDRFQ4gxaiOSWStAUsNBM4_vR%3DS7Hwg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
/*
Build command:
clang-cl test_tesseract.cpp -Xclang -std=c++17 -IF:/win64_llvm/include
F:\win64_llvm\lib\leptonica-1.78.0.lib F:\win64_llvm\lib\tesseract41.lib
Run:
test_tesseract.exe mueller
*/
#include <string>
#include <iostream>
#include <filesystem>
#include <leptonica/allheaders.h>
#include <tesseract/baseapi.h>
namespace fs = std::filesystem;
PIX * check_roration(PIX *pixs) {
l_int32 orient, alt_rot = 0;
l_float32 upconf1, leftconf1;
PIX *fpixs;
fpixs = pixConvertTo1(pixs, 130);
pixOrientDetect(fpixs, &upconf1, &leftconf1, 0, 0);
makeOrientDecision(upconf1, leftconf1, 0, 0, &orient, 1);
if (orient == L_TEXT_ORIENT_UNKNOWN) {
// printf("Confidence is low; no determination is made. "
// "But maybe there is %d deg rotation.\n", alt_rot);
} else if (orient == L_TEXT_ORIENT_UP) {
// printf("Text is rightside-up.\n");
alt_rot = 0;
} else if (orient == L_TEXT_ORIENT_LEFT) {
// printf("Text is rotated 90 deg ccw.\n");
alt_rot = 90;
} else if (orient == L_TEXT_ORIENT_DOWN) {
// printf("Text is upside-down.\n");
alt_rot = 180;
} else { /* orient == L_TEXT_ORIENT_RIGHT */
// printf("Text is rotated 90 deg cw.\n");
alt_rot = 270;
}
pixDestroy(&fpixs);
if (alt_rot) {
PIX *pixd;
pixd = pixRotateOrth(pixs, alt_rot/90);
pixs = pixCopy(NULL, pixd);
pixDestroy(&pixd);
}
return pixs;
}
int main(int argc, char* argv[]) {
int pages = 15; // limit number of process pages
if(argc != 2) {
fprintf(stderr, "You need to provide directory as argument!\n" );
exit(-1);
}
std::string path = argv[1];
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
int idx=0;
for (const auto & entry : fs::directory_iterator(path)) {
const char *filename = entry.path().string().c_str();
Pix *image = pixRead(filename);
if(image == NULL) {
fprintf(stderr, "Error reading image %s!\n", filename);
exit(2);
}
image = check_roration(image);
printf("%s\n", filename);
api->SetImage(image);
char *outText = api->GetUTF8Text();
printf("OCR output:\n%s", outText);
api->Clear();
if (outText)
delete [] outText;
printf("\t1");
if (filename)
delete [] filename;
printf("\t2");
if (image)
pixDestroy(&image);
printf("\t3");
if(idx > pages) {
api->End();
exit(10);
}
idx++;
}
api->End();
exit(0);
}