首页 > 解决方案 > 检测特定文本的 xy 坐标

问题描述

我尝试使用 Tasker 和 AutoTools 插件在 Android 中为我的游戏编写自动化程序。此时还可以,但我需要捕获屏幕截图并需要根据我的需要对其进行解释。

这正是我所需要的;

有些文字在游戏中很重要,我想在屏幕上的任何地方点击它。所以我认为我需要 OCR 来完成这项任务。我遵循一些解决方案,但每次都失败或卡住。让我解释一下我尝试了哪些解决方案。

遵循解决方案 1:

遵循解决方案 2:

此时有什么建议?

我应该学习android并编写自己的应用程序吗?

标签: androidocrtasker

解决方案


您应该查看ocr-reader Google 示例。它运行速度很快,而且得到你想要的东西并不难。您需要做的是修改OcrDetectorProcess样本附带的,将文本分解为单个单词,然后您可以轻松计算每个单词的边界和中心点。这里有一些代码可以帮助您入门:

@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
    mGraphicOverlay.clear();

    // Get all detected items.
    SparseArray<TextBlock> items = detections.getDetectedItems();
    for (int i = 0; i < items.size(); ++i) {
        TextBlock item = items.valueAt(i);

        // Get individual lines in each item.
        List<Line> lines = (List<Line>) item.getComponents();
        for (Line line : lines) {

            // Get individual "words" in each line.
            List<Element> elements = (List<Element>) line.getComponents();
            for (Element e : elements) {

                // Now get the position of each element.
                Rect rect = e.getBoundingBox();
                Point[] points = e.getCornerPoints();
                int centerX = (points[0].x + points[2].x) / 2;
                int centerY = (points[0].y + points[2].y) / 2;

                // DO STUFF

            }
        }
    }
}

推荐阅读