ocr
Recognizes text in a specified screen region or window, matches expected text, and returns screen-absolute coordinates for clicking; saves a screenshot on failure.
Instructions
OCR 识别文本并给屏幕绝对坐标(可直接用于点击)。只对给定 ROI 做(实测整屏 4.1s vs ROI 数十 ms)。
matched_count==0 是「本次没找到」而非「不存在」;
save_on_failure 可在没匹配到时留下截图证据。
这是「弱视觉」的主力:验收时绝大多数判断只需要 「屏幕上有没有这几个字、它在哪」。
只对给定的区域做 OCR(实测整屏 2560x1440 要 4.1 秒,而 ROI 通常几十毫秒)—— 这也是同类项目的标配做法。
坐标一律是屏幕绝对坐标,可直接喂给点击;coordinate_space
字段会明说是 screen_absolute,避免「拿裁剪图坐标去点」这个经典坑。
匹配 expected 时的语义(重要):
· matched_count == 0 的意思是「本次没找到」,
不等于「游戏里没有」—— 可能界面还没加载、或文字被 OCR
拆成了多个框。返回里的 note 会写明这一点。
· best_match 取的是置信度最高的那条,不是第一条。
Args:
region: "x,y,w,h" 屏幕绝对坐标;与 window 二选一。
window: 窗口标题子串;用它定 ROI。
expected: 期望出现的文本;给了就把命中的单独列出来。
match: contains(默认)/ exact / regex。
threshold: 置信度下限,低于它的丢弃(默认 0.3)。
case_sensitive: 文本匹配是否区分大小写。
max_items: 最多返回多少个文本框。
save_on_failure: 给了路径时,若没匹配到就把当时的截图存到这里
(等价 MaaFramework 的 save_on_error)—— 失败要留证据。
Returns: {ok, engine, count, results: [{text, score, box, center, click_point}], texts, matched, matched_count, best_match, click_point, coordinate_space: "screen_absolute", image, ...}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| match | No | contains | |
| region | No | ||
| window | No | ||
| expected | No | ||
| max_items | No | ||
| threshold | No | ||
| case_sensitive | No | ||
| save_on_failure | No |