In fact, I initialized tesseract once, and I release the tesseract object 
in destructor ... I earned ~25 MB ... 

On Tuesday, June 25, 2019 at 10:02:34 AM UTC+3, _ Flaviu wrote:
>
> I have modified the code as follow:
>
> CTemp::CTemp()
> {
> m_Tess.Init(_T("C:\\tessdata-master\\"), _T("eng"), 
> tesseract::OcrEngineMode::OEM_TESSERACT_LSTM_COMBINED);
> }
>
> CTemp::~CTemp()
> {
> m_Tess.Clear();
> m_Tess.End();
> m_Tess.ClearPersistentCache();
> }
>
> BOOL CTemp::GetTextFromImage(CString sFileName)
> {
> PIX* pix = NULL;
>
> do
> {
> // read image
> PIX* pix = pixRead(sFileName);
> if (! pix)
> {
> m_sError.Format(_T("Cannot open input file: %s."), sFileName);
> break;
> }
> // recognize
> m_Tess.SetImage(pix);
> }
> while (FALSE);
>
> // cleanup
> pixDestroy(&pix);
>
> return m_sError.IsEmpty();
> }
>
>
> The same result, (only 10MB less).
>
> On Monday, June 24, 2019 at 8:40:26 PM UTC+3, zdenop wrote:
>>
>> I am sorry I miss understand your code: I was expecting that in 
>> do/while loop you are iterating over file list. IMO its inefficient to 
>> initialize tesseract for each image. 
>>
>>
>> Zdenko 
>>
>> po 24. 6. 2019 o 11:06 _ Flaviu <[email protected]> napísal(a): 
>> > 
>> > I think there no loop there, it is just an do/while(FALSE), those Clear 
>> and pixDestroy is called every time when an images are read. 
>> > 
>> > On Monday, June 24, 2019 at 11:52:11 AM UTC+3, zdenop wrote: 
>> >> 
>> >> And also  pixDestroy should be in loop too. You just create new 
>> objects and you did not destroy them, so why you wander you run out of 
>> memory? 
>> >> 
>> >> 
>> >> Zdenko 
>> >> 
>> >> 
>> >> po 24. 6. 2019 o 10:35 Zdenko Podobny <[email protected]> napísal(a): 
>> >>> 
>> >>> IMHO you should call  Clear in loop with  SetImage : 
>> https://github.com/tesseract-ocr/tesseract/blob/master/src/api/baseapi.h#L675
>>  
>> >>> 
>> >>> Zdenko 
>> >>> 
>> >>> 
>> >>> po 24. 6. 2019 o 10:25 _ Flaviu <[email protected]> napísal(a): 
>> >>>> 
>> >>>> I come in just in time: I have developed a little test application, 
>> which have debug and release, source code, and exe. 
>> >>>> 
>> >>>> Here is the code that get text from images: 
>> >>>> 
>> >>>> BOOL CTemp::GetTextFromImage(CString sFileName) 
>> >>>> { 
>> >>>> PIX* pix = NULL; 
>> >>>> tesseract::TessBaseAPI Tess; 
>> >>>> 
>> >>>> do 
>> >>>> { 
>> >>>> if (Tess.Init(_T("C:\\tessdata-master\\"), _T("eng"), 
>> tesseract::OcrEngineMode::OEM_TESSERACT_LSTM_COMBINED)) 
>> >>>> { 
>> >>>> m_sError.Format(_T("OCRTesseract: Could not initialize 
>> tesseract.")); 
>> >>>> break; 
>> >>>> } 
>> >>>> // read image 
>> >>>> PIX* pix = pixRead(sFileName); 
>> >>>> if (! pix) 
>> >>>> { 
>> >>>> m_sError.Format(_T("Cannot open input file: %s."), sFileName); 
>> >>>> break; 
>> >>>> } 
>> >>>> // recognize 
>> >>>> Tess.SetImage(pix); 
>> >>>> } 
>> >>>> while (FALSE); 
>> >>>> 
>> >>>> // cleanup 
>> >>>> pixDestroy(&pix); 
>> >>>> Tess.Clear(); 
>> >>>> Tess.End(); 
>> >>>> 
>> >>>> return m_sError.IsEmpty(); 
>> >>>> } 
>> >>>> 
>> >>>> Of course, you have put tessdata-master folder in C: 
>> >>>> 
>> >>>> The test app has an menu item: File->Read images, and from that 
>> CFileDialog you can select multiple image file, and you can see the state 
>> of reading in the statusbar. 
>> >>>> 
>> >>>> If you intend to run this project on you machine, you have modify 
>> yourself the paths in project settings. No big deal. The project is a 
>> VS2017 project, MFC. 
>> >>>> 
>> >>>> I run this app on few Win10 64bit machines, with the same results. I 
>> have loaded for my tests 14 images, and after all image has been converted, 
>> the test app took 466 MB, and after these 14 images has been loaded again, 
>> the app took 883 MB, after I loaded again, 1307 MB, and so on ... the only 
>> way to free RAM is to stop the app and start again ! Sad :( 
>> >>>> 
>> >>>> Here is the link for attachements: 
>> https://1drv.ms/f/s!AtSPCxnvttzegw6QHz8RAOjJq8fe 
>> >>>> 
>> >>>> 
>> >>>> On Monday, June 24, 2019 at 10:53:40 AM UTC+3, zdenop wrote: 
>> >>>>> 
>> >>>>> AFAIR: there were always problem with windows tesseract debug build 
>> (MSVC). Release version works fine, but debug failed. So it would be great 
>> if somebody experienced with windows debugging have a look at this. 
>> >>>>> 
>> >>>>> Zdenko 
>> >>>>> 
>> >>>>> 
>> >>>>> ne 23. 6. 2019 o 20:29 _ Flaviu <[email protected]> napísal(a): 
>> >>>>>> 
>> >>>>>> Ok, good idea, I am working right now on a simple testing app that 
>> prove the issue. I will come back as soon as I can. 
>> >>>>>> 
>> >>>>>> On Thursday, June 20, 2019 at 2:02:12 PM UTC+3, _ Flaviu wrote: 
>> >>>>>>> 
>> >>>>>>> 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/e338cc87-e7c3-4bb0-bd94-632185e25652%40googlegroups.com.
>>  
>>
>> >>>>>> 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/00b7d682-befa-46d9-8c44-e349c5824d03%40googlegroups.com.
>>  
>>
>> >>>> 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/ddea01e6-dcdd-4f17-932c-363d46d25fc4%40googlegroups.com.
>>  
>>
>> > 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/8fd1acd7-1c49-483d-bfc3-273b1b59dd8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to