【问题标题】:Unsupported image format. May need to install JAI Image I/O package不支持的图像格式。可能需要安装 JAI Image I/O 包
【发布时间】:2017-06-16 13:21:16
【问题描述】:

我正在尝试使用 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

【问题讨论】:

  • 您要读取什么类型的图像文件?
  • 我尝试使用 jpg 和 png 文件。两种格式都出现同样的错误。
  • 您能否将有问题的图像文件之一发布到 imgur,以便我们尝试使用 ImageIO 加载它?
  • 附上上题中的jpg文件。
  • 傻我!我传递了错误的文件名...我不小心用变量名硬编码了文件名。但我现在面临 java.lang.UnsatisfiedLinkError... 试图解决这个问题。不过感谢您的快速回复!

标签: java maven tesseract jai tess4j


【解决方案1】:

它无法为给定的文件格式确定合适的 ImageReader。所以可能是 1)无法正确确定文件格式(奇怪的文件扩展名?)或 2)没有为您尝试使用的格式注册图像阅读器。

ImageIO.getImageReaderByFormatName

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-02
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 2021-12-20
    • 1970-01-01
    • 2016-02-24
    相关资源
    最近更新 更多