Menu

“Need to install JAI Image I/O package.” error when using tess4j in Scala SBT project in IntelliJ IDEA

Help
bugfoot
2017-03-03
2019-11-08
  • bugfoot

    bugfoot - 2017-03-03

    I added all JARs (specifically including jai-imageio-core-1.3.1.jar) under Tess4J/dist and Tess4J/lib folders as well as the tessdata folder from version Tess4J-3.3.0 into an IntelliJ IDEA Scala SBT project.

    However, I get a java.lang.RuntimeException: Need to install JAI Image I/O package. https://java.net/projects/jai-imageio/ exception when trying to run the following code in a Scala worksheet:

    import java.io.File
    import net.sourceforge.tess4j._
    
    val imageFile = new File("MyImageFile.PNG")
    val instance = new Tesseract()
    instance.setDatapath("MyTessdataFolder")
    
    val result = instance.doOCR(imageFile)
    print(result)
    

    even though jai-imageio-core-1.3.1.jar is properly included in the project.

     

    Last edit: bugfoot 2017-03-04
  • Quan Nguyen

    Quan Nguyen - 2017-03-03

    Do you have success with the bundled sample images?

     
  • bugfoot

    bugfoot - 2017-03-04

    Yes, they all give the expected results in the same Scala project.

     
  • Quan Nguyen

    Quan Nguyen - 2017-03-04

    It could be something with your image that jai-imageio cannot read. It may need rescan or preprocessing.

     
  • bugfoot

    bugfoot - 2017-03-04

    I suspect something else is causing the error, since I tried my original Scala worksheet script with paths to your eurotext.png and eurotext.tif test images (instead of "MyImageFile.PNG") found in Tess4J\test\resources\test-data\ (with which your Java test ran without errors in my Scala project), but I got a different error this time:

    ERROR net.sourceforge.tess4j.Tesseract - Unsupported image format. May need to install JAI Image I/O package.
    https://java.net/projects/jai-imageio/
    java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I/O package.
    https://java.net/projects/jai-imageio/
        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 A$A6$A$A6.result$lzycompute(temp.sc:13)
        at A$A6$A$A6.result(temp.sc:13)
        at A$A6$A$A6.get$$instance$$result(temp.sc:13)
        at A$A6$.main(temp.sc:32)
        at A$A6.main(temp.sc)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jetbrains.jps.incremental.scala.local.WorksheetInProcessRunnerFactory$WorksheetInProcessRunnerImpl$$anonfun$loadAndRun$1$$anonfun$apply$3.apply(WorksheetInProcessRunnerFactory.scala:102)
        at org.jetbrains.jps.incremental.scala.local.WorksheetInProcessRunnerFactory$WorksheetInProcessRunnerImpl$$anonfun$loadAndRun$1$$anonfun$apply$3.apply(WorksheetInProcessRunnerFactory.scala:97)
        at scala.Option.map(Option.scala:146)
        at org.jetbrains.jps.incremental.scala.local.WorksheetInProcessRunnerFactory$WorksheetInProcessRunnerImpl$$anonfun$loadAndRun$1.apply(WorksheetInProcessRunnerFactory.scala:96)
        at org.jetbrains.jps.incremental.scala.local.WorksheetInProcessRunnerFactory$WorksheetInProcessRunnerImpl$$anonfun$loadAndRun$1.apply(WorksheetInProcessRunnerFactory.scala:80)
        at scala.Option.foreach(Option.scala:257)
        at org.jetbrains.jps.incremental.scala.local.WorksheetInProcessRunnerFactory$WorksheetInProcessRunnerImpl.loadAndRun(WorksheetInProcessRunnerFactory.scala:79)
        at org.jetbrains.jps.incremental.scala.remote.Main$.make(Main.scala:69)
        at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:24)
        at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)
    net.sourceforge.tess4j.TesseractException: java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I/O package.
    https://java.net/projects/jai-imageio/
        at net.sourceforge.tess4j.Tesseract.doOCR(temp.sc)
        at net.sourceforge.tess4j.Tesseract.doOCR(temp.sc)
    Output exceeds cutoff limit.
    
     

    Last edit: bugfoot 2017-03-04
  • bugfoot

    bugfoot - 2017-03-07

    I tried the very same code snipped as in the original post, except this time in a Scala class instead of a Scala worksheet, and now it worked, so I guess this has something to do with the worksheet, I'll investigate. Thank you for the help so far.

     
  • Sławomir Kliś

    Sławomir Kliś - 2017-08-06

    I've got similar problem in Java + Servicemix/Camel. Error is thrown from net.sourceforge.tess4j.util.ImageIOHelper. The class is trying to collect something image readers/writers by image type. So from line #100 "Unsupported image format." is thrown if there was not any reader found for the image type (for me - if I trying to open tiff). The magic "Need to install JAI Image I/O package" is thrown not because there is no jar available the reason is different and the library is in place. Any image is to be opened the util tries to convert it to tiff format. So in line #121 it collects all available image writers by image type for 'tiff'. Problem is that there is not any (other image types work properly and the list has elements). If the list is empty the magic "Need to install JAI Image I/O package" error is thrown in the line #124.

    I've installed libtiff into the system (ubuntu) and it seems tesseract throws less wornings (it was warking before though ) but the curse is still there.

     
  • Rahul Dubey

    Rahul Dubey - 2018-02-14

    I am facing the same problem while using tess4j

    java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I/O package.
    https://java.net/projects/jai-imageio/
    at net.sourceforge.tess4j.util.ImageIOHelper.getIIOImageList(ImageIOHelper.java:408)
    at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:224)
    at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:208)
    at com.purpose.all.Strip.c1.isScan(c1.java:113)
    at com.purpose.all.Strip.c1.checkpdf(c1.java:155)
    at com.purpose.all.Strip.c1.main(c1.java:39)

    i have included repository
    
    <!-- https://mvnrepository.com/artifact/com.github.jai-imageio/jai-imageio-core -->
    

    <dependency>
    <groupId>com.github.jai-imageio</groupId>
    <artifactId>jai-imageio-core</artifactId>
    <version>1.3.1</version>
    </dependency>

    But still this problem exist , how can I fix this?

     
  • Rahul Dubey

    Rahul Dubey - 2018-02-15

    Problem solved , this issue is due to my corrupted jar.

     
  • vijayalangaram

    vijayalangaram - 2019-11-07

    @Rahul @bugfoot Dubey hi i have same error and unable to solve . I was added jar,depedency.

    It's Perfectly working for local image file and Is it possible for stored image in mongodb ?

    public static void main(String[] args) {
            SpringApplication.run(JavalocaldoocrApplication.class, args);       
            Mongo mongodb = new MongoClient("localhost", 27017);        
            DB db = mongodb.getDB("test-db");   
            DBCollection collection = db.getCollection("user");     
                   **File image = new File("mongodb://localhost:27017//test-db//user");**   
            Tesseract tessInst = new Tesseract();          
              //        tessInst.setDatapath("C:\Program Files (x86)\Tesseract-OCR\tessdata");
            final String datapath =  "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata";                
            tessInst.setDatapath (new File("datapath").getPath());   
            try {
                  String result= tessInst.doOCR(image);
                  System.out.println(result);
               } catch (TesseractException e) {
                  System.err.println(e.getMessage());
             }       }}
    

    Can please guide me !!

     

    Last edit: vijayalangaram 2019-11-07

Log in to post a comment.