Menu

Tess4J and Maven

2016-07-19
2020-01-24
  • Thomas Denson

    Thomas Denson - 2016-07-19

    Hi Team,

    I'm having some issues using the maven version of Tess4J.
    I've created a new project, added the tess4j maven dependency. 3.2.1
    And tried to run the example code from the website and I get the following error:

    21:58:11.838 [main] ERROR net.sourceforge.tess4j.Tesseract - Input not set!
    java.lang.IllegalStateException: Input not set!
        at com.github.jaiimageio.impl.plugins.tiff.TIFFImageReader.getNumImages(TIFFImageReader.java:259)
        at net.sourceforge.tess4j.util.ImageIOHelper.getIIOImageList(ImageIOHelper.java:366)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:213)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:197)
        at Main.main(Main.java:18)
    java.lang.IllegalStateException: Input not set!
    

    Sample code:

    import java.io.File;
    
    import net.sourceforge.tess4j.ITesseract;
    import net.sourceforge.tess4j.Tesseract;
    import net.sourceforge.tess4j.TesseractException;
    
    public class Main {
    
        public static void main(String[] args) {
            File imageFile = new File("test.tif");
            ITesseract instance = new Tesseract();  // JNA Interface Mapping
            // ITesseract instance = new Tesseract1(); // JNA Direct Mapping
    
            try {
                String result = instance.doOCR(imageFile);
                System.out.println(result);
            } catch (TesseractException e) {
                System.err.println(e.getMessage());
            }
        }
    }
    

    Pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>test</groupId>
      <artifactId>test</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <name>pkgo ocr app</name>
      <description>A ocr app to read pkgo images and calculate stats</description>
      <dependencies>
        <dependency>
            <groupId>net.sourceforge.tess4j</groupId>
            <artifactId>tess4j</artifactId>
            <version>3.2.1</version>
        </dependency>
      </dependencies>
    </project>
    

    Any help would be greatly appreciated

     
  • Quan Nguyen

    Quan Nguyen - 2016-07-19

    "Input not set!" means you have not set the input image file. It's most likely that the file does not exist at the specified location. Substituting with a full path will help you debug the issue better.

     
  • Balaji Devadoss

    Balaji Devadoss - 2019-12-19

    Hi I am able to run the java code with tesseract with below code in eclipse.

            Tesseract tesseract = new Tesseract(); 
            try { 
                String text1 = tesseract.doOCR(new File("C:\\Program Files (x86)\\Java\\jre1.8.0_231\\bin\\sample.png")); 
                System.out.print(text1);                    
            } 
            catch (TesseractException e) { 
                e.printStackTrace(); 
            }
    

    But when i make a jar file out of this and run it in Oracle forms it gives below error. kindly advice.

    16:09:10.149 [thread applet-oracle.forms.engine.Main-1] ERROR net.sourceforge.tess4j.Tesseract - No input source set!
    java.lang.IllegalStateException: No input source set!
        at com.sun.imageio.plugins.png.PNGImageReader.getNumImages(Unknown Source)
        at net.sourceforge.tess4j.util.ImageIOHelper.getIIOImageList(Unknown Source)
        at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
        at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
        at Today2class.init(Today2class.java:34)
        at oracle.forms.handler.UICommon.instantiate(Unknown Source)
        at oracle.forms.handler.UICommon.onCreate(Unknown Source)
        at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)
        at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)
        at oracle.forms.engine.Runform.processMessage(Unknown Source)
        at oracle.forms.engine.Runform.processSet(Unknown Source)
        at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
        at oracle.forms.engine.Runform.onMessage(Unknown Source)
        at oracle.forms.engine.Runform.sendInitialMessage(Unknown Source)
        at oracle.forms.engine.Runform.startRunform(Unknown Source)
        at oracle.forms.engine.Main.createRunform(Unknown Source)
        at oracle.forms.engine.Main.start(Unknown Source)
        at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.start(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    
     

    Last edit: Quan Nguyen 2019-12-20
  • Quan Nguyen

    Quan Nguyen - 2019-12-20

    You should not put your sample image in Java installation folder. Anyway, you need to verify the input file exist at the specified location.

    File file = new File(<path to your input image>)
    if (file.exists()) {
    ...
    }
    
     

    Last edit: Quan Nguyen 2019-12-20
  • Seth Whittaker

    Seth Whittaker - 2020-01-24

    Hi Team,

    I have the following scenario:
    Springboot application embeding Tess4J to run Tesseract OCR engine.
    Environment: VM in GCP running Linux (pending choosing the best distribution).
    * 2 GPU's available.

    I'd like to know if there is already a version of Tess4J compiled with OpenCL to make use of available GPU's or
    ... How can I build Tesseract OCR engine with OpenCL to use GPU's or
    ... Do I have any other options to use GPU's

    GPU = NVIDIA GPGPU

    ... please?

     

Log in to post a comment.