快速接入

三步完成,开始使用 TriEye OCR

1

部署 OCR 引擎

将 TE.lua 放到按键精灵手机版的插件目录,首次使用调用下载函数自动获取 OCR 引擎。

插件目录:/sdcard/MobileAnJian/plugin/ 或脚本同目录
Import "TE.lua" -- 首次使用,下载 OCR 引擎(只需执行一次) TE.socr_down()
2

启动服务

每次脚本运行时调用启动函数,插件会自动生成随机端口并启动服务进程。

-- 有授权 key 时 TE.socr_start("你的授权key") -- 或无 key 免验证模式(服务端自动判断) TE.socr_start()
3

调用识别

截图后调用对应的识别函数,解析返回的 JSON 结果。

snapshot("/sdcard/screen.png", 0, 0, 720, 1280) -- OCR 文字识别 Dim r1 = TE.socr("/sdcard/screen.png") -- OpenCV 找图 Dim r2 = TE.socr_opencv("/sdcard/screen.png", "/sdcard/btn.png") -- YOLO 目标检测 Dim r3 = TE.socr_yolo("/sdcard/screen.png", Array("person")) -- 解析结果 Dim tab = TE.JsonToTable(r1)

完整脚本框架

一个脚本内同时使用三种识别能力的完整示例。

Import "TE.lua" TE.socr_down() TE.socr_start() -- 空 key 交由服务端自动判断 Function 找文字(目标) snapshot("/sdcard/screen.png", 0, 0, 720, 1280) Dim r = TE.socr("/sdcard/screen.png") Dim t = TE.JsonToTable(r) If t And t["success"] Then For Each item In t["data"] If InStr(item["text"], 目标) > 0 Then Dim cx = (item["left"] + item["right"]) / 2 Dim cy = (item["top"] + item["bottom"]) / 2 Tap cx, cy Return True End If Next End If Return False End Function