问题描述
我试图在Java EE(Payara服务器)中使用Tess4J,这是可能的,如果是这样的话?
Im trying to use Tess4J in Java EE (Payara server), is this possible and if so how?
我得到的确切异常:
e =(net.sourceforge.tess4j.TesseractException)net.sourceforge.tess4j.TesseractException:java.lang.RuntimeException:需要安装JAI Image I / O包。
e = (net.sourceforge.tess4j.TesseractException) net.sourceforge.tess4j.TesseractException: java.lang.RuntimeException: Need to install JAI Image I/O package.https://java.net/projects/jai-imageio/
我已将 jai-imageio
添加到我的 pom.xml ,以及将其添加到Payara的模块中。
I have added the jai-imageio
to my pom.xml, as well as added it to the modules of Payara.
文件 pom.xml
<!-- https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j -->
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.4.1</version> <!-- used 3.4.2 as well -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.jai-imageio/jai-imageio-core -->
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.3.1</version>
<scope>runtime</scope> <!-- tried without this as well -->
</dependency>
将JAR添加到
`Payara\glassfish\modules`
Tess4J代码(如有任何改进)可以做到这一点,我们将不胜感激。)
Tess4J code (If any improvements can be made to this as well it would be appreciated).
ITesseract instance = new Tesseract();
instance.setDatapath(pLangaugePath); // C:\\t
instance.setLanguage(pLanguage); // eng
try {
File[] tifFiles = PdfUtilities.convertPdf2Png(pFile);
if (tifFiles != null) {
for (File tifFile : tifFiles) {
String ocrText = instance.doOCR(tifFile);
if (StringUtils.isNotBlank(ocrText)) {
ret.append(ocrText);
}
}
}
} catch (TesseractException e) {
LOG.error("Could not do ocr on image file created via pdf ", e);
}
也尝试过以下两个例子。
1。
Have tried the following 2 examples as well.1.
try (PDDocument document = PDDocument.load(pFile)) {
int totalPages = document.getNumberOfPages();
PDFRenderer renderer = new PDFRenderer(document);
for (int pi = 0; pi < totalPages; pi++) {
BufferedImage image = renderer.renderImageWithDPI(pi, 75);
String ocrText = instance.doOCR(image);
if (StringUtils.isNotBlank(ocrText)) {
ret.append(ocrText);
}
}
} catch (Exception e) {
LOG.error("Could not do ocr on pdf", e);
}
2.
try {
ITesseract instance = new Tesseract();
instance.setDatapath(pLangaugePath); // C:\\t
instance.setLanguage(pLanguage); // eng
String ocrText = instance.doOCR(pFile);
if (StringUtils.isNotBlank(ocrText)) {
ret.append(ocrText);
}
} catch (Exception e) {
LOG.error("Could not do ocr on image file created via pdf ", e);
}
研究:
发现此
推荐答案
Tess4J被称为不与Glassfish的工作由于由所述运行时异常JNA不可用 RESOURCE_PREFIX
字符串常量。此问题已在最新版本3.4.9(针对Tesseract 3.05.01)和4.0.2(针对Tesseract 4.0.0-beta.1)中得到修复。图书馆现在可以使用Glassfish的,或许似鲭水狼牙鱼服务器
Tess4J was known for not working with Glassfish due to the run-time exception caused by the unavailability of JNA RESOURCE_PREFIX
string constant. This issue has been fixed in the latest releases 3.4.9 (for Tesseract 3.05.01) and 4.0.2 (for Tesseract 4.0.0-beta.1). The library can now be used with Glassfish, and perhaps Payara Server.
您可能还需要包括 ImageIO.scanForPlugins(); $ OCR调用前的c $ c>语句。这是为了确保可以使用适当的
ImageReader
来读取输入图像。
You may also need to include ImageIO.scanForPlugins();
statement before the OCR call. That is meant to ensure the appropriate ImageReader
be available to read input images.
这篇关于尝试在Java EE中使用Tess4J时出现RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!