I am trying to extract Text from Image by Using OCR its not getting me any text instead of that its getting me %m when i write OCREngine.getText() thats not correct . Pls look at my code and tell me the proper solution .
My code is :
public static void main(String[] args) throws Exception
{
// The path to the documents directory.
// String dataDir = Utils.getDataDir(PerformOCROnImage.class);
String dataDir = “F:/OCR/test1.bmp”;
/// Set the paths
// String imagePath = dataDir + “Sampleocr.bmp”;
// Create an instance of OcrEngine
OcrEngine ocr = new OcrEngine();
// Set image file
ocr.setImage(ImageStream.fromFile(dataDir));
// Perform OCR and get extracted text
try {
if (ocr.process()) {
// System.out.println(“getText " + ocr.getText().toString()+”\n");
// System.out.println(“getPages " + ocr.getPages().length+”\n");
// System.out.println("getPreprocessedImages "+ocr.getPreprocessedImages().getTextBlocksImage());
// System.out.println(“getPages.toString “+ocr.getText() +”\n”);
IRecognizedTextPartInfo firstBlock = (IRecognizedTextPartInfo) ocr.getText().getPartsInfo()[0];
System.out.println(firstBlock.getBox().toString());
//Get the children of the first block that will the the lines in the block
IRecognizedPartInfo[] linesOfFirstBlock = firstBlock.getChildren();
//Retrieve the fist line from the collection of lines
IRecognizedTextPartInfo firstLine = (IRecognizedTextPartInfo)linesOfFirstBlock[0];
//Display the level of line
System.out.println(firstLine.getText());
//Retrieve the fist word from the collection of words
IRecognizedTextPartInfo firstWord = (IRecognizedTextPartInfo) firstLine.getChildren()[0];
//Display the level of word
System.out.println(firstWord.getText());
//Retrieve the fist character from the collection of characters
IRecognizedTextPartInfo firstCharacter = (IRecognizedTextPartInfo)firstWord.getChildren()[0];
//Display the level of character
System.out.println(firstCharacter.getText());
}
} catch (Exception e) {
e.printStackTrace();
}
}