首页 > 解决方案 > 我使用 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>

请建议我怎样才能得到正确的结果

标签: javaocrtess4j

解决方案


这是最佳实践,

在运行该 tess4j 命令之前,您需要进行更喜欢使用的图像处理(OpenCV)。 https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality

或者您可以选择 Google Ml KIT

https://firebase.google.com/docs/ml-kit/recognize-text


推荐阅读