在JavaEE中尝试使用Tess4J时出现运行时异常
我试图在JavaEE(Payara服务器)中使用Tess4J,这可能吗?如果可能,如何实现 我得到的完全例外: e=(net.sourceforge.tess4j.TesseractException)net.sourceforge.tess4j.TesseractException:java.lang.RuntimeException:需要安装JAI映像I/O包。 我已经将在JavaEE中尝试使用Tess4J时出现运行时异常,java,maven,jakarta-ee,tesseract,tess4j,Java,Maven,Jakarta Ee,Tesseract,Tess4j,我试图在JavaEE(Payara服务器)中使用Tess4J,这可能吗?如果可能,如何实现 我得到的完全例外: e=(net.sourceforge.tess4j.TesseractException)net.sourceforge.tess4j.TesseractException:java.lang.RuntimeException:需要安装JAI映像I/O包。 我已经将jai imageio添加到我的pom.xml中,并将其添加到Payara的模块中 文件pom.xml <
jai imageio
添加到我的pom.xml中,并将其添加到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>
Tess4J代码(如果可以对此进行任何改进,将不胜感激)
我也尝试了以下两个例子。
一,
研究:
找到这个
由于JNA
RESOURCE_PREFIX
string常量不可用而导致运行时异常,Tess4J也因不使用Glassfish而闻名。此问题已在最新版本3.4.9(适用于Tesseract 3.05.01)和4.0.2(适用于Tesseract 4.0.0-beta.1)中修复。该库现在可以与Glassfish一起使用,也许还可以与Payara服务器一起使用
您可能还需要包括
ImageIO.scanForPlugins()语句。这是为了确保适当的图像阅读器
可用于读取输入图像。您有开发和部署环境吗?库也安装在部署中了吗?是的,就我所知,您能详细说明我如何准确地检查它吗?您是否尝试过“Tess4J-3.4.3-src\Tess4J\Tess4J\resources\test data”文件夹中的示例文件?@Daefect91没有,我现在将尝试,谢谢。@Daefect91使用测试数据时出现相同问题
`Payara\glassfish\modules`
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);
}
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);
}
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);
}