问题描述
我正在尝试从图像中提取文本.问题是我正在使用下面给出的代码来处理图像并打印提取的文本.
I am trying to extract text out of an image. The issue is that I am using the below given code to process the image and print the extracted text.
public class Test {
public static void extractText(String filename)
// public static void main(String[] args)
{
System.setProperty("jna.library.path", "32".equals(System.getProperty("sun.arch.data.model")) ? "lib/win32-x86" : "lib/win32-x86-64");
File imageFile = new File("img_perspective.png");
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
// Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
当我使用main方法时,OCR引擎可以很好地工作并提取文本.但是,当我尝试将此主要方法转换为名为"extractText()"的方法并尝试从另一个类调用它时,它将引发异常:
When I use the main method, the OCR engine works very well and extracts the text. But when I am trying to convert this main method to the method named "extractText()" and trying to call it from another class, it throws exception:
org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.patternrecognition.preprocessing.Preprocessing] in context with path [/ImagePreprocessing] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: com.sun.media.imageio.plugins.tiff.TIFFImageWriteParam
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at com.patternrecognition.preprocessing.test.extractText(test.java:19)
我不知道这有什么问题.我使用与硬编码的文件名完全相同的代码.仅更改方法.
I don't know what is wrong with this. I am using exactly the same code with hardcoded filename. Only the method is changed.
这真令人沮丧.有人可以帮忙吗.
This is so frustrating. Can someone help please.
推荐答案
确保jai-imageio.jar
在类路径中.并在OCR之前致电ImageIO.scanForPlugins();
.
Make sure jai-imageio.jar
is in the classpath. And call ImageIO.scanForPlugins();
before OCR.
这篇关于OCR Tesseract-Tess4J表现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!