不支援的图片格式.可能需要安装JAI Image I/O软件包 [英] Unsupported image format. May need to install JAI Image I/O package

查看:290
本文介绍了不支援的图片格式.可能需要安装JAI Image I/O软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用tess4j maven依赖项将图像文件转换为文本.
pom.xml中的依赖项:-

I'm trying to convert an image file to text using tess4j maven dependency.
Dependency in 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;
}

但是,当我尝试执行程序时,总是遇到以下异常:

However, when I try executing my program, I always encounter below exception:

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等.另外,我已经尝试了该论坛上建议的所有解决方案,但无法解决此错误.
任何帮助,将不胜感激.

All required dependencies like jai, lept4j etc are present in my repository. Also I have tried all the solutions suggested on this forum but I'm unable to resolve this error.
Any help would be appreciated.

谢谢
更新:在此处附加文件- Jpg文件

Thanks
Update: Attaching the file here - Jpg file

推荐答案

它无法为给定的文件格式确定适当的ImageReader.因此,可能是1)无法正确确定文件格式(奇怪的文件扩展名?)或2)没有为您尝试使用的格式注册图像读取器.

It cannot determine an appropriate ImageReader for the given file format. So it's probably 1) the file format cannot be determined properly (weird file extension?) or 2) there is no image reader registered for the format you're trying use.

请参见 ImageIO.getImageReaderByFormatName .

这篇关于不支援的图片格式.可能需要安装JAI Image I/O软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆