0

I've tried this code and added the needed jar files but still I'm getting an error message like Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302'.

Is there a complete tutorial how to extract text and what things should be done to address the error? Any help is appreciated...

import net.sourceforge.tess4j.*;
import java.io.File;

public class ExtractTxtFromImg {
    public static void main(String[] args) {
        File imgFile = new File("C:\\Documents and Settings\\rueca\\Desktop\\sampleImg.jpg");
        Tesseract instance = Tesseract.getInstance();  // JNA Interface Mapping
        // Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping

        try {
            String result = instance.doOCR(imgFile);
            System.out.println(result);
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
}
demongolem
  • 9,474
  • 36
  • 90
  • 105
  • 1
    In addition to adding the jars, you also need to add the natives. You can do so with `Djava.library.path="C:\[absolute path to dir containing *.dll files and such]"` – Anubian Noob May 06 '14 at 00:57
  • I did it by following the steps from [here](http://stackoverflow.com/questions/10714785/giving-java-library-path-in-netbeans-for-dll-so-files). but still there is the error. I typed on VM Options -Djava.library.path="C:\Documents and Settings\rueca\Desktop\libtesseract302.dll". Is there something wrong? – Peter Rueca May 06 '14 at 01:38
  • Just `"C:\Documents and Settings\rueca\Desktop\"` is enough. You need to add the directory, not the files. – Anubian Noob May 06 '14 at 01:39
  • :/ no idea then... Are you sure you have all the right natives and that they're in the proper folder? – Anubian Noob May 06 '14 at 02:15
  • Yes. The exact file location is in **C:\Documents and Settings\rueca\Desktop\pet\thesis\resume evaluator\plugins\Tess4J**, and I typed **-Djava.path.library="C:\Documents and Settings\rueca\Desktop\pet\thesis\resume evaluator\plugins\Tess4J\"** on VM Options. Now I'm trying this [one](http://sourceforge.net/p/tess4j/discussion/1202294/thread/370d1e1e/). – Peter Rueca May 06 '14 at 02:30
  • I don't understand this one **I have move the dll and the testdata to the top of the projectstructure (working directory of the project)** – Peter Rueca May 06 '14 at 02:32
  • If this didn't help you I don't know, sorry. :/ – Anubian Noob May 06 '14 at 02:44

1 Answers1

1

In addition to adding the jars, you also need to add the natives. You can do so with Djava.library.path="C:\[absolute path to dir containing *.dll files and such]"

Note that you need to provide the directory, not the file itself.

Anubian Noob
  • 13,426
  • 6
  • 53
  • 75