【问题标题】:Tess4j Image readingTess4j 图像读取
【发布时间】:2017-07-19 09:19:50
【问题描述】:

我正在使用 tess4j api 读取数字图像。

代码如下:

public static void main(String[] args) {
    // TODO Auto-generated method stub
    
       final File imageFile = new File("C:\\Users\\goku\\Desktop\\myimage.png");
        System.out.println("Image found");
       final ITesseract instance = new Tesseract();
        instance.setTessVariable("tessedit_char_whitelist", "0123456789");
        instance.setDatapath("C:\\Users\\goku\\Downloads\\Tess4J"); 
        instance.setLanguage("eng");
        String result;
        try {
            result = instance.doOCR(imageFile);
            System.out.println(result);
        } catch (TesseractException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       

}

附上图片。

程序将数字读取为错误。找不到问题。

输出:

1 1 3 251

问候, 瓦苏

【问题讨论】:

    标签: ocr tesseract tess4j


    【解决方案1】:

    将图像重新缩放到 300 DPI 会得到正确的结果。

    【讨论】:

      【解决方案2】:

      这是使用im4java (imagemagick) 正确编辑图像以便可以使用tess4j (tesseract) 读取的方法:

      private static File processImage(File img) throws IOException {
          File newImg = File.createTempFile("asdf", ".png");
      
          ImageMagickCmd cmd = new ImageMagickCmd("convert");
          IMOperation op = new IMOperation();
      
          op.addImage(img.getAbsolutePath());
          op.strip().resample(300).colorspace("gray").autoLevel().threshold(35000).type("bilevel").depth(8).trim();
          op.addImage(newImg.getAbsolutePath());
          cmd.run(op);
      
          return newImg;
      }
      

      【讨论】:

        【解决方案3】:

        可能是经过训练的数据。我使用了来自 https://digi.bib.uni-mannheim.de/tesseract/ 的 tesseract-ocr-w64-setup-v4.1.0.20190314.exe Windows 二进制文件中的训练数据,数据路径设置如下

        instance.setDatapath("C:\\Program Files\\Tesseract-OCR\\tessdata");
        

        我确实收到有关分辨率的警告,但结果是正确的: 471871882819

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-29
          • 2013-06-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多