Question

So I've set up my Eclipse and the necessary libraries to get Tess4J working, however, it's giving me an error when I use the provided example code. The imagefile is right there in the root of the workspace and I even tried moving it around and even editing the method to point directly to the path. All to no avail. I'm a bit stumped, to be honest and was wondering if someone might have an idea where I need to be looking.

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

public class Main {

    public static void main(String[] args) {
        File imageFile = new File("eurotext.tif");
        Tesseract instance = Tesseract.getInstance();  // JNA Interface Mapping
        // Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping

        try {
            String result = instance.doOCR(imageFile);
            System.out.println(result);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }
}

The error I'm getting is the following:

Feb 11, 2014 11:05:13 AM net.sourceforge.tess4j.Tesseract doOCR
SEVERE: Input not set!
java.lang.IllegalStateException: Input not set!
    at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getNumImages(TIFFImageReader.java:268)
    at net.sourceforge.vietocr.ImageIOHelper.getIIOImageList(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at Main.main(Main.java:12)

java.lang.IllegalStateException: Input not set!

Thanks in advance!

EDIT: Quick update, as I've been trying to figure out a lot of stuff and trying out multiple things. First of all, I've figured out that the input not set is caused by a wrongly placed .dll file. However, now I've run into a new and much more difficult error. Here is the new code (I merely added a println to verify if it is able to read the file before it goes into the try-catch).

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

public class Main {

    public static void main(String[] args) {
        File imageFile = new File("C:\\Users\\Marouane Boutaib\\Java projects\\Tess4j\\eurotext.tif");
        Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
        // Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
        System.out.println(imageFile.canRead());
        try {
            String result = instance.doOCR(imageFile);
            System.out.println(result);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }
}

However, with this I'm getting a new error:

true
Exception in thread "main" java.lang.UnsatisfiedLinkError: %1 is not a valid Win32 application.

    at com.sun.jna.Native.open(Native Method)
    at com.sun.jna.Native.open(Native.java:1759)
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
    at com.sun.jna.Library$Handler.<init>(Library.java:147)
    at com.sun.jna.Native.loadLibrary(Native.java:412)
    at com.sun.jna.Native.loadLibrary(Native.java:391)
    at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.init(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at Main.main(Main.java:12)

My colleagues and me think it's a missing reference, however, I've followed the guide to setting it up and I didn't alter at all from the example code given by Tess4J's developers themselves. On top of that, I have not yet found another instance on Google where this has happened and has been solved.

Was it helpful?

Solution

I know it's been too long but...

Firstly, make sure that you use 32-bit JVM.

Secondly, insert all the dlls (gsdll32.dll, liblept168.dll, libtesseract302.dll) in a certain folder and then use the

System.setProperty("jna.library.path", "<the directory of the folder without a trailing slash>"). 

After that it is going to work. I has occurred to me too...

OTHER TIPS

Input not set => Problem

I solved it with those steps :

Step 1: Check eng.traineddata file. if file is not available means download.

Step 2: After completion of download. Just paste in project file. Or Create tessdata folder and paste into it.

This is fixed code :

package ocr_rec;

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

public class Test {
   public static void main(String[] args) {
        File imageFile = new File("C:\\Users\\Vigne\\OneDrive\\Desktop\\files\\data.jpg");
        ITesseract instance = new Tesseract(); 
        System.err.println(instance.getClass().getName().toString());
        try {
            String result = instance.doOCR(imageFile);
            System.out.println(result);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top