TomatoOCR
访问TomatoOCR官网
说明
TomatoOCR 在 2.1.5 版本以上内置
识别屏幕文字 你还可以看看
vision屏幕文字识别(screen.visionOcr)
paddle屏幕文字识别(screen.paddleOcr)
一个例子
local tomatoOCR = require("TomatoOCR")
function ocr_start(x1, y1, x2, y2, zi)
local rec_type = "ch-3.0";
-- 注:ch、ch-2.0、ch-3.0版可切换使用,对部分场景可适当调整
-- "ch":普通中英文识别,1.0版模型
-- "ch-2.0":普通中英文识别,2.0版模型
-- "ch-3.0":普通中英文识别,3.0版模型
-- "number":数字识别
-- "cht":繁体,"japan":日语,"korean":韩语
tomatoOCR.setRecType(rec_type)
tomatoOCR.setDetBoxType("rect") -- 调整检测模型检测文本参数- 默认"rect": 由于手机上截图文本均为矩形文本,从该版本之后均改为rect,"quad":可准确检测倾斜文本
tomatoOCR.setDetUnclipRatio(1.9) -- 调整检测模型检测文本参数 - 默认1.9: 值范围1.6-2.5之间
tomatoOCR.setRecScoreThreshold(0.1) -- 识别得分过滤 - 默认0.1,值范围0.1-0.9之间
tomatoOCR.setReturnType("json")
-- 返回类型 - 默认"json": 包含得分、坐标和文字;
-- "text":纯文字;
-- "num":纯数字;
-- 自定义输入想要返回的文本:".¥1234567890",仅只返回这些内容
tomatoOCR.setBinaryThresh(0) -- 二值化设定,非必须
tomatoOCR.setFilterColor("", "black"); -- 设置滤色值和背景色(black\white),滤色值默认是空的,详细使用见方法说明
local type = 3;
-- type 可传可不传
-- type=0 : 只检测
-- type=1 : 方向分类 + 识别
-- type=2 : 只识别
-- type=3 : 检测 + 识别
-- 只检测文字位置:type=0
-- 全屏识别: type=3或者不传type
-- 截取单行文字识别:type=1或者type=2
local img = "/var/mobile/Media/1.png"
screen.image(x1, y1, x2, y2):saveToPngFile(img)
local res = tomatoOCR.ocrFile(img, type)
print("结果:"..res)
-- 找字返回坐标,返回的是“百度”的中心点坐标,没有找到字返回“”空字符串
local point = tomatoOCR.findTapPoint(zi)
print(point)
-- 找字返回坐标,返回所有的“百度”的中心点坐标,没有找到字返回“”空字符串
local points = tomatoOCR.findTapPoints(zi)
print(points)
end
function main()
local path = "/var/mobile/Media/svip/"
-- 初始化-ios
tomatoOCR.init(path.."/res/")
local license = "" -- 授权码
local remark = "" -- 备注
local flag = tomatoOCR.setLicense(license, remark)
print(flag)
ocr_start(0, 0, 300, 300, "百度")
end
main()