In my previous example i have shows you how can we read an image on the web page and prints the text on it. Now lets see how we can read an image which is in your hard driver and prints the texts on it .
same as previous blog post m using the same "OCR" class but with different methods. Just copy and paste this code and try your self. But make sure you have a file in "D:\\TEST\\123.jpg" this location or you can just change the file location to where ever you want :)
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import javax.imageio.ImageIO;
import com.asprise.util.ocr.OCR;
public class Test2 {
//Read text values on an image
public static void main(String[] args) throws Exception {
//Create a new object from BufferImage class and assign the image location
BufferedImage image = ImageIO.read(new File("D:\\TEST\\123.jpg"));
//Read the image characters
String imageText = new OCR().recognizeCharacters((RenderedImage) image);
//Prints the image text
System.out.println("Text From Image : \n"+ imageText);
//Prints the length of the text
System.out.println("Length of total text : \n"+ imageText.length());
}
}
My actual image is
And the code output is
Text From Image :
ABCDEFG
Length of total text :
9
now you can try this code with your images to see the result. Do read my next blog post to see how we can read a bar code with this.

No comments:
Post a Comment