我正在尝试使用tess4j maven dependency将图像文件转换为文本。
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
发布于 2017-06-16 21:32:49
它无法确定给定文件格式的适当ImageReader。所以可能是1)文件格式无法正确确定(奇怪的文件扩展名?)或者2)没有为您尝试使用的格式注册的图像阅读器。
https://stackoverflow.com/questions/44590329
复制相似问题