Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

malloc error while using Tesseract with OpenCL option enabled

I have compiled Tesseract 3.04.00 with the OpenCL option enabled. While trying to extract text from an image using GetUTF8Text(), there is a malloc error, a memory leak I suppose.

I found a patch for a memory leak error that was previously added, however, the version I have compiled already has the patch added. I am not sure as to why the memory leak has occurred.

This is the output I am getting:

[DS] Profile read from file (tesseract_opencl_profile_devices.dat).
[DS] Device[1] 1:Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz score is 14049349632.000000
[DS] Device[2] 1:HD Graphics 5000 score is 14049349632.000000
[DS] Device[3] 0:(null) score is 21474836480.000000
[DS] Selected Device[2]: "HD Graphics 5000" (OpenCL)
ACP(15114,0x7fff795bf300) malloc: *** mach_vm_map(size=1125865547108352) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

Has anyone faced this problem before? How do I fix this?

like image 589
Raghav Avatar asked Apr 10 '15 09:04

Raghav


2 Answers

I'm not familiar with Tesseract, but I suspect the patch that you referred was for a different issues.

Looking in the output details, It looks like you are using an apple computer. Please take a look at link below which contains some 'how to' for installing and using Tesseract on Mac OS X: https://ryanfb.github.io/etc/2015/03/18/experimenting_with_opencl_for_tesseract.html

Hope this is useful to fix the issue. Anyway, the error "can't allocate region" means that there is no memory space left. Indeed has been required a huge quantity of memory (size=1125865547108352, about 1.126 Petabyte). To figure out what is really happening, you should profile the code using a profiling tool like gdb (indeed the error message says "set a breakpoint in malloc_error_break to debug"), or at least upload a little program that can be used to reproduce the issue.

like image 87
prisco.napoli Avatar answered Oct 05 '22 09:10

prisco.napoli


You ran out of memory. (error code=3) "can't allocate region" means malloc tried to allocate more memory than was available..

Maybe you can try to restrict recognition to a sub-rectangle of the image - call SetRectangle(left, top, width, height) after SetImage. Each SetRectangle clears the recogntion results so multiple rectangles can be recognized with the same image. E.g.

  api->SetRectangle(30, 86, 590, 100);

Without seeing your code, I'd guess either you are not destroying objects and releasing memory or there is a bug with that version. To check if it's the former you can use a memory leak detection tool/library, to check if it is the later you can debug it or just try using a different version..

like image 21
rmp Avatar answered Oct 05 '22 10:10

rmp