java - 我使用 tess4j 从图像中提取文本但没有得到正确的结果
问题描述
我使用了 tess4j 但没有得到正确的结果。下面是我的代码。
public static String crackImage(String filePath) {
BufferedImage img = null;
try {
img = ImageIO.read(new File(filePath));
} catch (IOException e) {
}
ITesseract instance = new Tesseract();
instance.setLanguage("eng");
// instance.setPageSegMode((3));
img= ImageHelper.convertImageToGrayscale(img);
instance.setDatapath("C:\\tessdata");
try {
String result = instance.doOCR(img);
return result;
} catch (TesseractException e) {
System.err.println(e.getMessage());
return "Error while reading image";
}
}
我附上了示例图片。
我的输出是:
臂米方式:a;男人
mFL/Vemmnh 1951 mm 8221 11m 3521|\|\|II\IIIIIIHIIIIHIIIH
人渣——万维网
%'</p>
请建议我怎样才能得到正确的结果
解决方案
这是最佳实践,
在运行该 tess4j 命令之前,您需要进行更喜欢使用的图像处理(OpenCV)。 https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality
或者您可以选择 Google Ml KIT
推荐阅读
- java - 在数组旁边显示平均值
- python - 将 Jupyter 中的“DataFrame.style”表保存为 png?
- jquery - 在下拉更改时显示 Bootstrap 模态表单,并在插入数据库后选择该值
- c - 有人可以帮我解决这个问题吗?(我是编程新手)
- google-analytics - 如何跟踪来自 url1->url2->url3 的用户数量?
- laravel - Laravel pluck 没有返回排序数组作为数据库
- excel - 如何为特定工作表运行此宏,工作簿有很多工作表?
- html - 如何通过自定义 CSS 为移动设备制作粘性标题
- visual-studio - 如何使用 Visual Studio 扩展处理深色主题?
- python - 空 SPARQL 查询结果