Perform OCR using Java

The Optical Character Recognition (OCR) technology has made it possible to recognize and read the text within the scanned documents and images. OCR lets you convert the read-only text into an editable form. The converted text can further be processed for operations such as text analysis. In this article, I’ll show you how to perform OCR on images (PNG, JPG, BMP, and GIF) and convert images to text using Java OCR API - Aspose.OCR for Java.

Tip: You may be interested in a free Text to GIF Converter that allows you to generate animations from texts.

Java OCR API - Installation

Aspose.OCR for Java can be downloaded as a JAR or installed within a Maven-based application using the following configurations.

Repository:

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>

Dependency:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-ocr</artifactId>
    <version>20.5</version>
</dependency>

Convert Image to Text using Java

Most often, the images for OCR are the pages of scanned documents, invoices, receipts, bills and etc. where the text is composed of multiple lines. In such scenarios, you need to retrieve the whole text from the image. The following are the steps to perform OCR on the image having multiple lines of text using Aspose.OCR for Java.

The following code sample shows how to perform OCR on image and convert image to text using Java.

Convert Images having Single Line of Text

In the previous example, we have performed OCR on an image having multiple lines of text. However, there could be a case when the image contains a single line of text. For such a case, you can configure the API accordingly. The following are the steps to convert an image having a single line of text.

The following code sample shows how to perform OCR on an image having a single line of text using Java.

Conclusion

In this article, you have seen how to convert PNG, JPG, BMP, and GIF images to text using Java OCR API. The code samples show how to perform OCR on images having single or multiple lines of text within Java applications. You can learn more about Aspose’s Java OCR API using documentation.

See Also