How to extract Text from Images ?
By using Asprise Java OCR(optical character recognition) we can extract Text and barcode information from scanned documents.
Follow below steps to extract text from Image:
Add Asprise Java OCR as maven dependency to your project.
<dependency>
<groupId>com.asprise.ocr</groupId>
<artifactId>java-ocr-api</artifactId>
<version>15.3.0.1</version>
</dependency>
After adding maven dependency,below is code we can use:
import java.awt.*;
import java.awt.image.RenderedImage;
import java.net.URL;
import com.asprise.ocr.Ocr;
import javax.imageio.ImageIO;
public class voculabaru {
public static void main(String args[]) throws Exception {
//here we are starting OCR engine Ocr.setUp(); Ocr ocr = new Ocr(); ocr.startEngine("eng", Ocr.SPEED_FASTEST); String imageURL = "https://1.bp.blogspot.com/-cxzu35QNkWo/Xs_3L_qikpI/AAAAAAAABBY/kPh-YT_Ojx0pclqcw6QN2j-uuWlZZ16LACLcBGAsYHQ/s1600/image_text.png"; URL url = new URL(imageURL); Image image = ImageIO.read(url); String s = ocr.recognize((RenderedImage) image, "all", "text"); System.out.println("Text From Image : \n" + s); System.out.println("Length of total text : \n" + s.length()); } }
Where imageURL is my input image(below image) where i will extract text.
Run the code then we see output like below:
Text From Image :
You are always
stronger than
you think you
are
Length of total text :
47
Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.