Java net.sourceforge.tess4j从图像读取数据时抛出错误结果
我正在尝试使用OCR(光学字符重组)。 我有一个样本图像,我想从中读取数据。下面是我的示例图像文件 我使用了Java net.sourceforge.tess4j从图像读取数据时抛出错误结果,java,ocr,tess4j,Java,Ocr,Tess4j,我正在尝试使用OCR(光学字符重组)。 我有一个样本图像,我想从中读取数据。下面是我的示例图像文件 我使用了tess4jAPI从图像中读取文本。请找到下面的代码 public static String crackImage(String filePath) { File imageFile = new File(filePath); ITesseract instance = new Tesseract(); instance.setLangu
tess4j
API从图像中读取文本。请找到下面的代码
public static String crackImage(String filePath) {
File imageFile = new File(filePath);
ITesseract instance = new Tesseract();
instance.setLanguage("eng");
try {
String result = instance.doOCR(imageFile);
return result;
} catch (TesseractException e) {
System.err.println(e.getMessage());
return "Error while reading image";
}
}
public static void main(String[] args) {
String results = crackImage("D:\\data\\testImage.PNG");
System.out.print(results);
}
下面是我在pom.xml文件中的依赖项
<dependencies>
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
我不确定,即使我明确地将语言设置为英语,为什么会打印此文本。有人能帮我解决这个问题吗。看起来图像需要一些预处理。将其转换为灰度或黑白可能会有所帮助。@nguyenq:我试过用几个图像。所有这些都给了我类似的结果。但我没有尝试将图像转换为灰度或黑白。我会尝试一下。谢谢您能否提供一些如何预处理图像的示例。请尝试Tess4J提供的
ImageHelper.convertImageToGrayscale
方法。看起来图像需要一些预处理。将其转换为灰度或黑白可能会有所帮助。@nguyenq:我试过用几个图像。所有这些都给了我类似的结果。但我没有尝试将图像转换为灰度或黑白。我会尝试一下。谢谢您能提供一些如何预处理图像的示例吗?请尝试Tess4J提供的ImageHelper.convertImageToGrayscale
方法。
Creale a Voumhe metauzoa mwwer usmg szz