【问题标题】:How to extract the text coordinates in an image using tess4j如何使用 tess4j 提取图像中的文本坐标
【发布时间】:2017-06-01 05:46:15
【问题描述】:

我试图弄清楚在 tess4j 执行 OCR 之后如何在文本图像中获取坐标和单词 rect。我是初学者,所以有人可以帮我分解一下吗?非常感谢。

【问题讨论】:

    标签: image-processing ocr tesseract


    【解决方案1】:

    我自己对 tess4j 还很陌生,我不想不同意 @nguyenq,但我是这样做的

    String imageUrl = "...";
    File imageFile = new File(imageUrl);
    Image image = ImageIO.read(imageFile);
    BufferedImage bi = toBufferedImage(image);
    ITesseract instance = new Tesseract();
    
    for(Word word : instance.getWords(bi, ITessAPI.TessPageIteratorLevel.RIL_TEXTLINE)) {
      Rectangle rect = word.getBoundingBox();
    
      System.out.println(rect.getMinX()+","+rect.getMaxX()+","+rect.getMinY()+","+rect.getMaxY()
                        +": "+word.getText());
    }
    

    这是我的 toBufferedImage 方法

    public static BufferedImage toBufferedImage(Image img)
    {
      if (img instanceof BufferedImage)
      {
          return (BufferedImage) img;
      }
    
      // Create a buffered image with transparency
      BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    
      // Draw the image on to the buffered image
      Graphics2D bGr = bimage.createGraphics();
      bGr.drawImage(img, 0, 0, null);
      bGr.dispose();
    
      // Return the buffered image
      return bimage;
    }
    

    SO credit

    编辑我应该注意到这是使用 tess4j v3.3.1。 @nguyenq 在最初的问题发布后必须添加这个新的便利 API

    【讨论】:

      【解决方案2】:

      Tess4J 的单元测试包括获取已识别词的边界框的示例。代码类似于Tess4J: How to use ResultIterator?

      【讨论】:

      • 非常感谢。我是否有机会获得完整的示例代码?只是一个非常简单的。 (我可以说,我非常喜欢你 Quan Nguyen。)
      • 单元测试可以在项目的代码库中找到:sourceforge.net/p/tess4j/code/181/tree/Tess4J_3/trunk/test/net/…
      • 测试用例 testResultIterator 代表了一个确定边界框的完整示例。代码相当简单——你应该能够遵循它。
      • 非常感谢。很大的帮助!
      • 我尝试执行 tessiterator 代码,我见证了以下错误:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多