Aspose OCR jar file

Hi There,

We are trying to use OCR to recognize some text from an image. For trying this out I downloaded the Aspose OCR for java from Aspose website. But there is no .jar file in it and it only has expanded folder structure with class files. And when I try to use it with the following code snippet

AsposeOCR api = new AsposeOCR();

	// Recognize page from BufferedImage
	try {
		BufferedImage loaded = ImageIO.read(new File("Converted_PDF_Image21.jpg"));
		String result = api.RecognizePage(loaded);
		System.out.println("Result BufferedImage: " + result);
	} catch (IOException e) {
		e.printStackTrace();
	}

we are getting the following error
Exception in thread “main” java.lang.NoClassDefFoundError: ai/onnxruntime/OrtException
at PerformOCR.main(PerformOCR.java:13)

Please let us know where to download the jar file and also how to resolve this issue.

Thanks,
Mani

@Mani_Alagappan

You may please download the JAR file from Aspose Repository. In case you still face any issue, please feel free to let us know.

Hi There,

Thanks. I am able to download the .jar file now. But I am still getting this error
Exception in thread “main” java.lang.NoClassDefFoundError: ai/onnxruntime/OrtException

When I execute this code snippet.

Thanks,
Mani

@Mani_Alagappan

Aspose.OCR for Java has dependency on " Onnxruntime" which should be resolved as well. Please try to following guidelines in installation section of the documentation and update your pom.xml file accordingly.

Hi There,

I am able to read some of the texts from the image now. But I am getting a lot of output like the following along with the actual result.

[W:onnxruntime:, graph.cc:814 onnxruntime::Graph::Graph] Initializer cnn.conv5.weight appears in graph inputs and will not be treated as constant value/weight. This may fail some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.

Do you know why this is happening and how to resolve this?

Thanks,
Mani

@Mani_Alagappan

The issue does not seem related to the API abd actual reason is unknown. It seems environment related issue. Would you please share some environment details with us e.g. JDK Version, IDE Name, sample Image, Application Type, etc. We will test the scenario in our environment and address it accordingly.

Hi There,

I am testing it with a stand alone java program before using it in our application. So I wrote a simple java program with the following code and executed it from command prompt.

import com.aspose.ocr.*;
import ai.onnxruntime.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

class PerformOCR
{
	public static void main(String[] args) 
	{
		System.out.println("Hello World!");
		String file = "Aspose.Total.Java.lic"; //change the path to point to a valid license
		License.setLicense(file);
		AsposeOCR api = new AsposeOCR();

		// Recognize page from BufferedImage
		try {
			BufferedImage loaded = ImageIO.read(new File("Sample_Image.jpg"));
			String result = api.RecognizePage(loaded);
			System.out.println("Result BufferedImage: " + result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

The system os is Windows 10 and JDK version is 1.8.0_211. I downloaded onnxruntime-1.31.jar to run this.Sample_Image.jpg (687.0 KB)
Herewith I have attached the sample image I used to test.

Thanks,
Mani

@Mani_Alagappan

We are testing the scenario using command prompt and facing a different exception i.e. java.lang.NoClassDefFoundError. We will further investigate it and share our feedback with you soon.

I got the same error and then I downloaded onnxruntime-1.3.1 jar from microsoft site and included in my class path. After that it ran fine but was displaying that warning message 100s of times in the output.

Thanks,
Mani

@Mani_Alagappan

Meanwhile we are checking it, would you kindly try to use following version of onnxruntime and share the results with us:

  • onnxruntime-1.2.0-1.5.3.jar

Hi There,

If I download and use this, I am getting the following error.
Exception in thread “main” java.lang.UnsatisfiedLinkError: no jnidnnl in java.library.path

It was working fine with 1.3.1 jar wit some warnings in the output.

Thanks,
Mani

@Mani_Alagappan

We were able to replicate the issue that you have mentioned about the warnings and logged it as OCRJAVA-45 in our issue tracking system. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

PS: The issue does not occur while running a Maven Project in Eclipse or IntelliJ IDEA

Hi There,

Thanks for the update. Can you please let me know what are the jars I should include in Eclipse, so that I can try it out in Eclipse or please send me the zip of your eclipse project if possible so that I can setup the same way in my side.

Thanks,
Mani

@Mani_Alagappan

The onnxruntime-1.3.1.jar has debug messages and we recommend to use a maven build project in order to use Aspose.OCR for Java. You can create a maven project in Eclipse or IntelliJ IDEA and specify following in your pom.xml:

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-ocr</artifactId>
    <version>20.5</version>
</dependency>
<dependency>
   <groupId>org.bytedeco</groupId>
   <artifactId>onnxruntime-platform</artifactId>
   <version>1.2.0-1.5.3</version>
</dependency>

You can also download a sample project from our GitHub Repository and run it in your environment. In case you face any issue, please feel free to let us know.

Hi There,

Thanks for the reply. When I tried with the example zip file in Eclipse it worked fine. So I added the missing jars to my classpath and then my stand alone program worked fine too.

set classpath=%CLASSPATH%;./onnxruntime-1.2.0-1.5.3-windows-x86_64.jar;./onnxruntime-platform-1.2.0-1.5.3.jar;./dnnl-1.3-1.5.3-windows-x86_64.jar;./dnnl-platform-1.3-1.5.3.jar;./javacpp-1.5.3-windows-x86_64.jar;./javacpp-platform-1.5.3.jar;

When I run the program, I get most of the results but not all when compared to the result I got when I tried your Cloud example. Following is what I get from my program

  1. Objective and Scope
    1.1 The objective of this Design Vérification (DV) and Stability Plan is t
    activities trequired to verify the performnance of the SNAP Foam Dressing.
    veérification activities will include activities to verify SNAP product
    requirements and activities to support SNAP product shelf life claims.
    1.2. The scope of this DV & Stability Plan applies to the SNAP product lis
    7
    NOTE: Product revision level used during testing will be specified in the applica
  2. Background
    3 Reference Documents

Whereas when I tried your cloud option and uploaded the same image I also got the content from sections 1.1.1, 1.1.2, 1.1.2.1.1 etc. in the image. Do you know why there is a difference? Also looks like it is not able t read the contents inside the table in the image.

Thanks,
Mani

@Mani_Alagappan

We also noticed the issue in our environment and logged it as OCRJAVA-46 in our issue tracking system. We will surely check this and keep you posted with the status of its resolution. Please spare us some time.

We are sorry for the inconvenience.