We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Ocr Error

I am Facing some problems while using aspose.ocr library in netbeans. The programm is given below and the problems too.

package ocr;

import com.aspose.ocr.ImageStream;
import com.aspose.ocr.OcrEngine;
import java.io.*;

public class OCR {

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

com

.aspose.ocr.OcrEngine engine=new com.aspose.ocr.OcrEngine();
String image=“D:\ocr.bmp”;
String resource=“H:\Software\java_jdk\aspose-ocr-17.01-java.zip”;
engine
.setResource(new FileInputStream(resource));
engine
.setImage(ImageStream.fromFile(image));
com
.aspose.ocr.Ilanguage language=Language.lead(“English”);
engine</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">getLanguages</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">().</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">addLanguage</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">language</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">);</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">
engine</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">process</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">();</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">
</span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; color: rgb(43, 145, 175);">System</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">out</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">print</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">engine</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">getText</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">());</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: rgb(48, 51, 54);">

}

}
<p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”>Problems: 1. In the line " engine.setResource(new FileInputStream(resource));" I am getting the message regarding “setResource “<ol start=“2” style=“margin: 0px 0px 1em 30px; padding: 0px; border: 0px; font-size: 15px; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”>
  • In the line " com.aspose.ocr.Ilanguage language=Language.lead(“English”);”…I am getting two errors regarding language
  • <p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”>3.in the line " engine.getLanguages().addLanguage(language);” …I am getting error regarding laguage.<p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”>
    <p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”>
    <p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”>Please help me.
    Hi,

    Thank you for your inquiry and sharing details.

    This is to update you that if you want to perform OCR operation on a scanned image containing writing other than English, it requires loading language specific resources. Language specific resources for .Net & Java are same. English is the default language that needs no settings. The resources can be downloaded from link Resources. Following is the sample Java code snippet:

    String imagePath = "french_sample.jpg";
    OcrEngine ocr = new OcrEngine();
    ocr.setImage(ImageStream.fromFile(imagePath));

    ocr.getLanguageContainer().clear();
    ocr.getLanguageContainer().addLanguage(com.aspose.ocr.LanguageFactory.load("French_language_resource_file_for_Aspose.OCR_for_.NET_3.2.0.zip"));
    if (ocr.process())
    {
    System.out.println(ocr.getText());
    }
    else
    {
    System.out.println("Error reading image");
    }

    Hope the above information helps. Feel free to contact us in case of any query or comments.