2017-06-16 62 views
0

我試圖將圖像文件轉換爲使用tess4j maven依賴項的文本。
依賴在pom.xml中: -不支持的圖像格式。可能需要安裝JAI圖像I/O包

<!-- 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

+1

你試圖閱讀什麼類型的圖像文件? – VGR

+0

我試着用JPG和PNG文件。兩種格式都有相同的錯誤。 – Anuja

+0

你可以發佈一個有問題的圖像文件imgur,所以我們可以嘗試加載ImageIO? – VGR

回答

0

它無法確定給定文件格式的適當的ImageReader。所以它可能是1)文件格式無法正確確定(奇怪的文件擴展名?)或2)沒有爲您嘗試使用的格式註冊圖像閱讀器。

參見ImageIO.getImageReaderByFormatName

相關問題