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:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 -->
You should open a new question, rather than reviving an old post, as your problem seems not related to Tess4J but has more to do with reading file from MongoDB. Tess4J cannot process corrupted or invalid input image files.
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:even though
jai-imageio-core-1.3.1.jar
is properly included in the project.Last edit: bugfoot 2017-03-04
Do you have success with the bundled sample images?
Yes, they all give the expected results in the same Scala project.
It could be something with your image that
jai-imageio
cannot read. It may need rescan or preprocessing.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:
Last edit: bugfoot 2017-03-04
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.
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.
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)
<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?
Problem solved , this issue is due to my corrupted jar.
@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 ?
Can please guide me !!
Last edit: vijayalangaram 2019-11-07
You should open a new question, rather than reviving an old post, as your problem seems not related to Tess4J but has more to do with reading file from MongoDB. Tess4J cannot process corrupted or invalid input image files.
https://howtodoinjava.com/mongodb/java-mongodb-getsave-image-using-gridfs-apis/
https://www.mkyong.com/mongodb/java-mongodb-save-image-example/
https://www.technicalkeeda.com/java-mongodb-tutorials/java-mongodb-upload-download-delete-read-image-using-gridfs-api
https://api.mongodb.com/java/3.1/com/mongodb/gridfs/GridFSDBFile.html