OCR Java

Hi


I tried to extract text from image using aspose ocr jar.But I got the following error. Please help me.
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.aspose.ocr.internal.cf.a(Unknown Source)
at com.aspose.ocr.internal.cf.c(Unknown Source)
at com.aspose.ocr.internal.cf.b(Unknown Source)
at com.aspose.ocr.internal.mk.a(Unknown Source)
at com.aspose.ocr.internal.ci.a(Unknown Source)
at com.aspose.ocr.OcrEngine.setResource(Unknown Source)
at programmersguide.workingwithocr.performocronimage.java.PerformOCROnImage.main(PerformOCROnImage.java:38)

Hi Divya,


Thank you for contacting Aspose support.

It is recommended that you should set the Java Heap size to an appropriate value before performing OCR operation on an image. On my end, I have set it to 512M, and haven’t faced the said exception while executing your provided code snippet on a sample of my own. I would request you to give another try after setting the Java Heap size accordingly. In case the problem persists, please provide your sample so we could re-evaluate the scenario.

Hi


Thank you for your support. Te ocr engine works. But the extracted text in unreadable form.

I got the extracted text —> OcR \OT&< >=e R*?=*&*4 1^ & +=&^<*n+&x <+

instead of the following image.Please help me


Hi Divya,


Thank you for providing the sample image.

We are able to replicate the problem of incorrect text recognized from your provided sample while using the latest version of Aspose.OCR for Java 1.9.0. We have logged this problem in our bug tracking system under ticket OCR-33758, for further investigation and correction. Please spare us little time for proper analysis of the problem cause. In the meanwhile, we will keep you posted with updates in this regard.

Please accept our sincere apologies for the inconvenience caused.

Hi,


Is there any solution for the problem? How could i resolve it? Please Help

Hi Divya,


Thank you for writing back.

We need to thoroughly investigate the failure cause on our end then we will be in a better position to comment on what could have caused the incorrect recognition. Based on our initial investigation, we suspect the failure was caused due to the low image resolution because we recommend at least 300DPI images for OCR operation. Moreover, the font size should be at least 30PT for optimum accuracy.

We have scheduled the ticket for the upcoming release of Aspose.OCR for Java 2.0.0. We haven’t yet announced the release schedule, but as soon as we do, we will post here for your kind reference.

Thank you so much. When i tried with 300dpi it works… :slight_smile:

Hi Divya,


Good to know that you are up and running again. Please feel free to write back in case you have further questions or concerns.

Please note, we will keep the ticket open in our bug tracking system for further investigation, and in order to support low resolution images for OCR operations.

Hi,


Thank you for your support.I just want to know one more thing.

I’m developing a Java web application project. So where i place the Aspose.OCR.1.9.0.Resources.zip

file.Please help me

Hi Divya,


Thank you for writing back.

You can place the resource file in any folder on which your application as access rights. It would be more appropriate that you should place the resource file in the same folder as of aspose-ocr-x.x-jdk1x.jar file.

Please feel free to write back in case you face any difficulty.

Hi,


Thank you for your Support.

Its working fine in 64bit machine.

but in 32 bit OS I have the folowing error

Caused by: java.lang.OutOfMemoryError: Java heap space
at com.aspose.ocr.internal.cf.a(Unknown Source)
at com.aspose.ocr.internal.cf.c(Unknown Source)
at com.aspose.ocr.internal.cf.b(Unknown Source)
at com.aspose.ocr.internal.mk.a(Unknown Source)
at com.aspose.ocr.internal.ci.a(Unknown Source)
at com.aspose.ocr.OcrEngine.setResource(Unknown Source)

How could i solve this issue?

Hi Divya,


Could you please mention what is the Java Heap size set on your 32-bit platform? It is suggested that you should set the Java Heap size to at least 512m. In case you have less memory on the machine, please try setting the Java Heap to 128m, and give your code another try to see if you still can reproduce the problem.

Please feel free to write back in case you face any difficulty.

Hi…

I tried it in another two 64 bit machine… It works in one system and fails in other.
What is the actual reason for that? Is there any settings required fr this?
Please look my java setting.

Hi Diyva,


I have created a VM of Windows 7 32-bit, and unfortunately, I was unable to see the problem as stated in your recent posts when Java Heap size is set to 512m. In order to troubleshoot this matter further, I would request you to please execute the following piece of code on the machine, in same project where you are experiencing OutOfMemoryException, and provide the output here.

Java

// Get current size of heap in bytes
long heapSize = Runtime.getRuntime().totalMemory();


// Get maximum size of heap in bytes. The heap cannot grow beyond this size.// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();


// Get amount of free memory within the heap in bytes. This size will increase // after garbage collection and decrease as new objects are created.
long heapFreeSize = Runtime.getRuntime().freeMemory();

Please note, you always have a finite max of heap to use no matter what platform you are running on. In Windows 32 bit this is around 2GB (not specifically heap but total amount of memory per process), whereas in Windows 64 bit you can set a higher heap size because 64 bit operating systems support more than 2GB of RAM.

In reference to Aspose.OCR for Java product, as you may see that the exception is arising on loading the resource file. The file its self is merely of 100MB but the OCR operation requires this file to be loaded in the memory while performing OCR on an image. Therefore 256M heap size should be enough to the load resource file only, although as you are loading the image as well, and the process it self require some memory to execute so it is wise to provide ample memory to the overall operation, such as setting the heap to 512M would be enough.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.