Java code to extract text from image

The OCR technology has become very popular and beneficial, especially for organizations that are going away from paper documents and want to extract important textual data from the scanned documents to save it into their existing business software. The healthcare industry, legal firms, or Local government agencies are converting their huge records into searchable digital documents.

Similarly, if you are looking for a strong but easy OCR Java library for your software project, you have landed at the right place. In this article, we will explain how to extract text from PNG images using Java. Hence, scan the paper documents like receipts, and passports, or take a shot of a car number plate and save all of them as PNG images. We will extract text from these documents one by one in the following sections.

The following points will be covered in this article:

Java PNG Text Extraction Library - Installation

In this section, we will discuss the installation procedure of this Java PNG text extraction library. If you are using Maven to manage a Java project or app, add the following configurations in the pom.xml file.

<repository>
	<id>ConholdateJavaAPI</id>
	<name>Conholdate Java API</name>
	<url>https://releases.conholdate.com/java/repo</url>
</repository>        
<dependency>
	<groupId>com.conholdate</groupId>
	<artifactId>conholdate-total</artifactId>
	<version>23.6</version>
	<type>pom</type>
</dependency>

Then run the following commands.

mvn clean    
mvn install -U

For configurations about other Java frameworks, please visit releases.conholdate.com.

Java Tutorial: Recognize and Extract Text from PNG

In this section, you will learn how to extract text from a PNG image using our Java PNG text extraction library. Merely, you need to write a few lines of code. Suppose we have a PNG image containing text like the below:

Recognize and Extract Text from PNG using Java
The following are the steps to extract text from a PNG using Java:

  1. Initialize an instance of AsposeOcr class.
  2. Get the text by using RecognizeImage(string fullPath) method of AsposeOcr class.
  3. Print or save the extracted text.

The code sample below demonstrates how to extract text from a PNG using Java.

Extract Text from a Receipt Image using Java

Many firms offer their employees to compensate for travel expenses, network fees, and other payments confirmed by receipts. So digitizing these receipts manually can be a hectic and time-consuming job. In this section, we will explain how easily you can digitize your receipts using our OCR Java library.

The following are the steps to extract text from a picture of a receipt using Java:

  1. Initialize an instance of AsposeOcr class.
  2. Create an object of ReceiptRecognitionSettings class.
  3. Specify the language using ReceiptRecognitionSettings.Language property.
  4. Get the text by using RecognizeReceipt(string, ReceiptRecognitionSettings) method of AsposeOcr class.
  5. Print or save the extracted text.

Following is the Java code to extract text from image (PNG).

Extracting Text from a Passport Photograph in Java

Passport recognition and verification automatically is commonly done in border control, banking, security, and many other sensitive departments. In this section, we will explain how quickly you can recognize and extract text from a photocopy of a passport.

The following are the steps to extract text from a PNG image of a passport using Java:

  1. Create an instance of AsposeOcr class.
  2. Initialize an object of PassportRecognitionSettings class.
  3. Set the language using PassportRecognitionSettings.Language property.
  4. Read the text by using RecognizePassport(string, PassportRecognitionSettings ) method of AsposeOcr class.
  5. Print or save the extracted text.

The code sample below shows how to extract text from a PNG image of a passport using Java.

Java Guide: Read Text from a Vehicle Number Plate Picture

In this section, we will demonstrate how to extract text from a picture of a car or any vehicle number plate.

The following are the steps to do the job:

  1. Initialize an instance of AsposeOcr class.
  2. Create an object of CarPlateRecognitionSettings class.
  3. Set the language using CarPlateRecognitionSettings.Language property.
  4. Extract the text by using RecognizeCarPlate(string, CarPlateRecognitionSettings) method of AsposeOcr class.
  5. Print or save the extracted text.

The code sample below demonstrates how to extract text from a PNG image of a vehicle number plate using Java.

Get a Free License

You can get a free temporary license to try the API without evaluation limitations.

Conclusion

To conclude, we hope you have learned how to recognize and extract text from PNG images in Java using our Java PNG text recognition and extraction library. We have demonstrated a simple Java tutorial to read text from a PNG. Likewise, we explained how to extract text from scanned copies of receipts, passports, and vehicle number plates.

You may visit the documentation to learn more about the Java Excel writer API.

Finally, please stay tuned at conholdate.com for regular updates.

Ask a Question

You can let us know your questions or queries on our forum.

See Also