ImageHelper

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Tess4j是一个基于Tesseract OCR引擎的Java库,可以用于识别图像中的文字。要获取图像中每个文字的坐标,可以使用Tess4j提供的`getWords()`方法。以下是获取图像中文字坐标的代码示例: ```java import java.awt.Rectangle; import java.io.File; import java.util.List; import net.sourceforge.tess4j.ITesseract; import net.sourceforge.tess4j.ITessAPI.TessPageIteratorLevel; import net.sourceforge.tess4j.Tesseract; import net.sourceforge.tess4j.Word; import net.sourceforge.tess4j.util.ImageHelper; public class Tess4jExample { public static void main(String[] args) { File imageFile = new File("example.png"); ITesseract tess = new Tesseract(); tess.setDatapath("tessdata"); try { String text = tess.doOCR(imageFile); System.out.println(text); List<Word> words = tess.getWords(ImageHelper.convertImageToPix(ImageIO.read(imageFile)), TessPageIteratorLevel.RIL_WORD); for (Word word : words) { Rectangle rect = word.getBoundingBox(); System.out.println(word.getText() + " @ (" + rect.x + "," + rect.y + ")"); } } catch (Exception e) { e.printStackTrace(); } } } ``` 在此示例中,我们首先使用`doOCR()`方法从图像中提取文本。然后,我们使用`getWords()`方法获取每个文字的`Word`对象,并使用`getBoundingBox()`方法获取每个`Word`对象的边界框。最后,我们打印每个文字及其坐标。注意,`getWords()`方法需要一个`Pix`对象,因此我们使用`ImageHelper.convertImageToPix()`方法将`BufferedImage`转换为`Pix`对象。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安得权

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值