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
- Recognize and extract text from PNG in java
- Extract Text from a Receipt Image
- Extracting Text from a Passport Photograph
- Text Extraction from a Vehicle Number Plate Picture
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:
The following are the steps to extract text from a PNG using Java:- Initialize an instance of AsposeOcr class.
- Get the text by using RecognizeImage(string fullPath) method of AsposeOcr class.
- Print or save the extracted text.
The code sample below demonstrates how to extract text from a PNG using Java.
// Instantiate an object of AsposeOcr class. | |
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr(); | |
// Read text from the PNG. | |
string result = recognitionEngine.RecognizeImage("source.png"); | |
// Print the extracted text. | |
Console.WriteLine(result); |
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:
- Initialize an instance of AsposeOcr class.
- Create an object of ReceiptRecognitionSettings class.
- Specify the language using ReceiptRecognitionSettings.Language property.
- Get the text by using RecognizeReceipt(string, ReceiptRecognitionSettings) method of AsposeOcr class.
- Print or save the extracted text.
Following is the Java code to extract text from image (PNG).
// Instantiate an object of AsposeOcr class. | |
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr(); | |
// Create an object of ReceiptRecognitionSettings class. | |
Aspose.OCR.ReceiptRecognitionSettings recognitionSettings = new Aspose.OCR.ReceiptRecognitionSettings(); | |
// Set the language | |
recognitionSettings.Language = Aspose.OCR.Language.Latin; | |
// Read the text from reciept image. | |
Aspose.OCR.RecognitionResult result = recognitionEngine.RecognizeReceipt("receipt.png", recognitionSettings); | |
// Print the extracted text. | |
Console.WriteLine(result.RecognitionText); |
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:
- Create an instance of AsposeOcr class.
- Initialize an object of PassportRecognitionSettings class.
- Set the language using PassportRecognitionSettings.Language property.
- Read the text by using RecognizePassport(string, PassportRecognitionSettings ) method of AsposeOcr class.
- Print or save the extracted text.
The code sample below shows how to extract text from a PNG image of a passport using Java.
// Instantiate an object of AsposeOcr class. | |
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr(); | |
// Create an object of ReceiptRecognitionSettings class. | |
Aspose.OCR.ReceiptRecognitionSettings recognitionSettings = new Aspose.OCR.ReceiptRecognitionSettings(); | |
// Set the language | |
recognitionSettings.Language = Aspose.OCR.Language.Latin; | |
// Read the text from reciept image. | |
Aspose.OCR.RecognitionResult result = recognitionEngine.RecognizeReceipt("receipt.png", recognitionSettings); | |
// Print the extracted text. | |
Console.WriteLine(result.RecognitionText); |
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:
- Initialize an instance of AsposeOcr class.
- Create an object of CarPlateRecognitionSettings class.
- Set the language using CarPlateRecognitionSettings.Language property.
- Extract the text by using RecognizeCarPlate(string, CarPlateRecognitionSettings) method of AsposeOcr class.
- 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.
// Instantiate an object of AsposeOcr class. | |
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr(); | |
// Create an object of ReceiptRecognitionSettings class. | |
Aspose.OCR.CarPlateRecognitionSettings recognitionSettings = new Aspose.OCR.CarPlateRecognitionSettings(); | |
// Set the language | |
recognitionSettings.Language = Aspose.OCR.Language.Latin; | |
// Read the text from number plate image. | |
Aspose.OCR.RecognitionResult result = recognitionEngine.RecognizeCarPlate("car-plate.png", recognitionSettings); | |
// Print the extracted text. | |
Console.WriteLine(result.RecognitionText); |
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.