Convert Image to Text Code Using Selenium Java


Convert Image to Text Code Using Selenium Java

There are a lot of cases where we need to read the images to get a text from it and used that for our test case execution or to just validate the text of the images.

In this article, we would be learning how we can read the data from the images.

To Read the data from images we need to use Java-OCR (Optical character recognition technology) library.

A Java OCR SDK Library API allows us to perform OCR and bar code recognition on images (JPEG, PNG, TIFF, PDF, etc.) and output as plain text, XML with full coordinate, searchable PDF or editable RTF.


To Start working with JAVA-OCR we need to follow the below steps:

1)    Download JAVA-Aspire OCR library from this link, depending upon your operating system.



2)    Unzip the downloaded folder and add the JAR file to your project directory. You can also download the maven dependency from this link.

3)    Most important from the downloaded zip folder copy the file named “aocr.jar” from the folder and place it inside C:\Windows\System32 also make sure to double click on this jar after we place on the path.

Below is the image I am trying to read


Below is the code snapshot I have mentioned comment as well.


The output of the above code execution is:





SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
May 16, 2019 at 11:39 AM

I am not able to see the code for this functionality. It would be great if getting the code snippet on this page

Reply
avatar
June 8, 2019 at 2:08 PM

Hey Ankur, code is not working and throwing error,

java.io.FileNotFoundException: C:\Users\Demo\AppData\Local\Temp\aocr_x64.dll (The process cannot access the file because it is being used by another process)

please help

Reply
avatar
June 15, 2019 at 8:24 PM

Hi Sujit,Error message is very clear and it says that file is currently being used may be its is open some where in background.Please recheck it correctly

Reply
avatar
July 30, 2019 at 10:21 PM

How to handle those captcha, which ask you to click on car images, bridge images?
any library for that too?

Reply
avatar
January 12, 2020 at 3:22 PM

In the event that you need to import mts to finished edition ace x, or import mts documents to imovie easily, you should change over the mts record to polished product genius and imovie well disposed configuration, as mov. AnyConv

Reply
avatar