我正在尝试使用tess4j maven依赖项将图像文件转换为文本 pom.xml中的依赖关系: -
<!-- OCR dependency -->
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.4.0</version>
<exclusions>
<exclusion>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
</exclusion>
<exclusion>
<groupId>net.sourceforge.lept4j</groupId>
<artifactId>lept4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.lept4j</groupId>
<artifactId>lept4j</artifactId>
<version>1.5.0</version>
</dependency>
我的代码: -
public String convertImageToText(String imageFilePath) throws TesseractException {
File imageFile = new File("imageFilePath");
ITesseract iTesseract = new Tesseract();
ImageIO.scanForPlugins();
String result = iTesseract.doOCR(imageFile);
System.out.println("Converted text is: "+result);
return result;
}
但是,当我尝试执行我的程序时,我总是会遇到以下异常:
Exception in thread "main" 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(Tesseract.java:215)
at utilities.HelperMethods.convertImageToText(HelperMethods.java:218)
at net.sourceforge.tess4j.util.ImageIOHelper.getIIOImageList(ImageIOHelper.java:408)
at utilities.HelperMethods.main(HelperMethods.java:250)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:196)
Caused by: java.lang.RuntimeException: Unsupported image format. May need to install JAI Image I/O package.
https://java.net/projects/jai-imageio/
at utilities.HelperMethods.convertImageToText(HelperMethods.java:218)
at net.sourceforge.tess4j.util.ImageIOHelper.getIIOImageList(ImageIOHelper.java:408)
at utilities.HelperMethods.main(HelperMethods.java:250)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212)
我的存储库中存在所有必需的依赖项,如jai,lept4j等。此外,我已尝试在此论坛上建议的所有解决方案,但我无法解决此错误 任何帮助,将不胜感激。
感谢
更新:在此处附加文件 - Jpg file
答案 0 :(得分:0)
无法为给定的文件格式确定合适的ImageReader。所以它可能是1)文件格式无法正确确定(奇怪的文件扩展名?)或2)没有图像阅读器注册您正在尝试使用的格式。