有没有可能使用像Tess4j或任何其他ORC这样的库来找到文本在屏幕上的矩形位置?
我需要做一个应用程序,可以找到一个按钮并单击它。
我在Tess4j文档中找不到任何东西。
发布于 2018-07-19 09:41:34
首先,你需要找到图片中的所有单词。
instance.getWords(bufferedImage, ITessAPI.TessPageIteratorLevel.RIL_TEXTLINE)我使用TessPageIteratorLevel.RIL_TEXTLINE来获取每一行的字符串。您可以使用TessPageIteratorLevel.RIL_WORD获取标记化字符串。
然后使用word.getBoundingBox();获取单词的边框。
public class DemoTess {
public static void main(String[] args) throws IOException {
ITesseract instance = new Tesseract();
instance.setLanguage("eng");
long start = System.currentTimeMillis();
BufferedImage bufferedImage = ImageIO.read(DemoTess.class.getResourceAsStream("/cv/menu_v1.png"));
for (Word word : instance.getWords(bufferedImage, ITessAPI.TessPageIteratorLevel.RIL_TEXTLINE)) {
if (word.getText().contains("Button Text")) {
Rectangle boundingBox = word.getBoundingBox();
System.out.println("boundingBox = " + boundingBox);
break;
}
}
System.out.println("time = " + (System.currentTimeMillis() - start));
}
}https://stackoverflow.com/questions/36794588
复制相似问题