Aspose.ocr with java

Hi all ,

I am using the below code for text recognition from an image(attached in the file attachments).

public static void main(String[] args) throws FileNotFoundException {

String imagePath = "./Image/Newwww.BMP";

String String resourcesFolderPath = ".\\resources\\Aspose.OCR.Resources.zip"; //(created a folder resources and copied Aspose.OCR.Resources.zip in it).

// Create an instance of OcrEngine , Modified the build path of my project by adding external jars.

OcrEngine ocr = new OcrEngine();

// Set Resources for OcrEngine

ocr.setResource(new FileInputStream(resourcesFolderPath));

// Set image file

ocr.setImage(ImageStream.fromFile(imagePath));

// Add language

ILanguage language = Language.load("english"); ocr.getLanguages().addLanguage(language);

// Perform OCR and get extracted text

try {

if (ocr.process())

{

System.out.println("\ranswer -> " + ocr.getText());

}

} catch (Exception e)

{

e.printStackTrace();

}

}

This was the output.


Output :

com.aspose.ocr.OcrException

: Error occurred during recognition.

at com.aspose.ocr.OcrEngine.a(Unknown Source)

at com.aspose.ocr.OcrEngine.process(Unknown Source)

at com.tcs.test.TextExtraction.main(

TextExtraction.java:51) //////(Line 51, i.e : if(ocr.process()) in my code)

Caused by: com.aspose.ocr.internal.bx: Error while loading 0 net (Network_12netsFS_Arial_BigAlphabet_18x18_8pt_468-26_v4L): Can't find resource "Network_12netsFS_Arial_BigAlphabet_18x18_8pt_468-26_v4L"

at com.aspose.ocr.aU.(Unknown Source)

at com.aspose.ocr.ae.c(Unknown Source)

at com.aspose.ocr.aK.(Unknown Source)

at com.aspose.ocr.an.a(Unknown Source)

... 3 more

Caused by:

java.lang.IllegalArgumentException: Can't find resource "Network_12netsFS_Arial_BigAlphabet_18x18_8pt_468-26_v4L"

at com.aspose.ocr.aE.a(Unknown Source)

... 7 more

Please help me how to resolve the error.

Thank you,

Divya.

Hi Divya,


Thank you for considering Aspose products.

By looking at the provided stack trace, we believe the error is caused due to the corrupted or incompatible resource archive. Please note, Aspose.OCR APIs use a version specific resource file, therefore if you are using any older version of the API with latest resource file or the other way around, you may encounter similar problems.

Please download & use the latest version of Aspose.OCR for Java 2.0.0 & it’s corresponding resource archive for your testing. Moreover, the current implementation of Aspose.OCR APIs work well with high resolution images having at least 300 DPI. Your provided image has the resolution of 96 DPI, and therefore returns garbage data when performed OCR operation with latest version.

Please feel free to write back in case you need our further assistance with Aspose APIs.