android - 检测特定文本的 xy 坐标
问题描述
我尝试使用 Tasker 和 AutoTools 插件在 Android 中为我的游戏编写自动化程序。此时还可以,但我需要捕获屏幕截图并需要根据我的需要对其进行解释。
这正是我所需要的;
有些文字在游戏中很重要,我想在屏幕上的任何地方点击它。所以我认为我需要 OCR 来完成这项任务。我遵循一些解决方案,但每次都失败或卡住。让我解释一下我尝试了哪些解决方案。
遵循解决方案 1:
- 我尝试了 AutoInput (Tasker plugin) UIQuery 方法但失败了。因为我认为 AutoInput 的 UIQuery 只适用于 android UI。无法从 3D 应用程序(如游戏)中获取任何信息。
遵循解决方案 2:
我搜索 OCR 解决方案并找到 AutoTools(Tasker 插件)
创建任务并截取屏幕截图并使用 AutoTools OCR 方法对其进行解释。没关系。AutoTools OCR 成功读取图像文件中的文本。
但我又卡住了。因为我成功地从图像文件中读取了文本,但我不知道重要文本的 xy 坐标。
此时有什么建议?
我应该学习android并编写自己的应用程序吗?
解决方案
您应该查看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
}
}
}
}
推荐阅读
- python - “[Errno 2] 没有这样的文件或目录:[文件名]”,同时尝试配置 twarc2 库以使用 Twitter api v2 获取 twitter 数据
- javascript - 如何在 React 中将道具从孩子传递给父母?
- javascript - 能否禁用该功能 scrollTop
- python - 为 Python 安装包的问题
- java - 我们如何在代码中实现 Hashtable 的初始容量和加载因子
- npm - NPM 未安装最新版本的软件包
- laravel - 在 laravel 中使用事务
- c - 函数的宏驱动条件第一个参数
- javascript - 尝试发出狙击命令但出现错误
- for-loop - 如果使用 for 循环生成多个文本框,如何在 Blazor 中获取文本框值并将其显示在 @onblur 事件的跨度中