例子: function main() { requestScreenShot(); var ret = ocr({region:[100, 100, 200, 130]}); console.log('ret:' + ret); }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
options | object | 选填,默认值:{region:[0, 0, 1, 1], bitmap: null, online:null, awesome:{threshold: 0.1, count: 3}} | region,指定区域[left, top, width, height],若取值在[0, 1]之间表示比例,例:0.5表示left位于屏幕x轴中点;若取值大于1表示像素值。默认值[0,0,1,1]。bitmap,如果为null则使用截屏后图片,否则直接使用该位图。online表示使用在线识别,比如:{url:'http://abc.com/api', key:'', secret:''},url表示服务器url,key和secret为可选鉴权参数。如果感觉ocr识别汉字偶尔会出错,请直接开启awesome,即可实现汉字识别99.999%成功率 awesome:{threshold:0.9, count: 3},threshold取值范围[0.5, 0.9], count取值范围[2, 6],如果开启awesome后还有汉字识别不对,请使用增量学习,把正确的语句添加到ocr文本库,然后点击「训练模型」,完成后下载模型,并打包进冰狐apk,即可正确识别对应的汉字。 |
例子: function main() { requestScreenShot(); var ret = ocr(); // 开启awesome,实现汉字100%成功率 // var ret = ocr({awesome:{threshold: 0.9, count: 4}}); console.log('ret:' + ret); }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
options | object | 选填,默认值:{region:[0, 0, 1, 1], bitmap: null} | region,指定区域[left, top, width, height],若取值在[0, 1]之间表示比例,例:0.5表示left位于屏幕x轴中点;若取值大于1表示像素值。默认值[0,0,1,1]。bitmap,如果为null则使用截屏后图片,否则直接使用该位图。 |
例子: function main() { requestScreenShot(); var ret = tessOcr({region:[0, 0, 0.5, 200]}); console.log('ret:' + ret); }
注意:如果您自己实现服务端需要接受post请求,body内容x-www-form-urlencoded格式,包含image(图片base64后的string)、key(string、可选)、secret(string、可选)
// 例子 function main() { requestScreenShot(); var r = ocr({online:{url:'http://xx.xx.xx.xx/api'}}) console.log('r:', r) var ret = ocrSwitchPage('其他无线连接', '个人热点', {online:{url:'http://xx.xx.xx.xx/api'}}) if (ret.length > 0) { console.log('进入成功') } else { console.log('进入失败') } }
例子: function main() { requestScreenShot(); var ret = ocrFindView('txt:数据分析|txt^:首页'); console.log('ret:' + ret); }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
tag | string | 必填 | 目标页面的tag,注意只能为text,多个文本使用|连接,找到任意一个即可,txt:表示精确搜索text为tag的控件,txt$:表示搜索text以tag结尾的控件,txt^:表示搜索text以tag开始的控件,txt*:表示搜索text包含tag的控件。例:'txt:我的|txt:首页'。 |
options | json object | {region:null, duration:500, maxStep:5, random: false, beforeWait:0, afterWait:0, failed: null, timeout: 1000, returnAllData: false, online:null, awesome:{threshold: 0.1, count:3}} | region可以在ocr时指定区域[left, top, width, height],注意:若取值在[0, 1]之间表示比例,例:[0.5, 100, 100, 200]表示left位于屏幕x轴中点;若取值大于1表示像素值。duration表示两次搜索的间隔时间,单位毫秒。maxStep表示当搜索失败时,重搜索的最大次数。beforeWait表示在搜索前等待的时间,单位毫秒。afterWait表示在搜索完成后等待的时间,单位毫秒。failed表示搜索控件失败后调用的函数,主要用于在操作期间出现弹窗的场景。timeout指ocr的超时时间,默认1000毫秒。online表示使用在线识别,比如:{url:'http://abc.com/api', key:'', secret:''},url表示服务器url,key和secret为可选鉴权参数。awesome:{threshold:0.9, count: 3},threshold取值范围[0.5, 0.9], count取值范围[2, 6]。 |
bitmap | Bitmap | 选填 | 默认为null,如果为null则使用截屏后图片,否则直接使用该位图 |
例子: function main() { requestScreenShot(); var ret = ocrClick('数据分析|首页'); console.log('ret:' + ret); }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
tag | string | 必填 | 目标页面的tag,注意只能为text,多个文本使用|连接,找到任意一个即可,txt:表示精确搜索text为tag的控件,txt$:表示搜索text以tag结尾的控件,txt^:表示搜索text以tag开始的控件,txt*:表示搜索text包含tag的控件。例:'txt:我的|txt:首页'。 |
options | json object | {region:null, clickMode:1, duration:500, maxStep:5, random: false, beforeWait:0, afterWait:0, failed: null, timeout: 1000, online:null, awesome:{threshold: 0.1, count:3}} | region可以在ocr时指定区域[left, top, width, height],注意:若取值在[0, 1]之间表示比例,例:[0.5, 100, 100, 200]表示left位于屏幕x轴中点;若取值大于1表示像素值。duration表示两次搜索的间隔时间,单位毫秒。maxStep表示当搜索失败时,重搜索的最大次数。beforeWait表示在搜索前等待的时间,单位毫秒。afterWait表示在搜索完成后等待的时间,单位毫秒。failed表示搜索控件失败后调用的函数,主要用于在操作期间出现弹窗的场景。timeout指ocr的超时时间,默认1000毫秒。 online表示使用在线识别,比如:{url:'http://abc.com/api', key:'', secret:''},url表示服务器url,key和secret为可选鉴权参数。awesome:{threshold:0.9, count: 3},threshold取值范围[0.5, 0.9], count取值范围[2, 6]。clickMode表示点击模式,1表示无障碍,2表示蓝牙,3表示usb,4表示root,5表示adb,如果使用蓝牙、usb、adb则需要先调用相应的初始化函数。 |
bitmap | Bitmap | 选填 | 默认为null,如果为null则使用截屏后图片,否则直接使用该位图 |
例子: function main() { requestScreenShot(); var ret = ocrSwitchPage('查看', '数据分析|首页'); console.log('ret:' + ret); }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
findTag/clickPosition | string/array | 必填 | findTag,表示需要点击的文本,注意只能为text,txt:表示精确搜索text为tag的控件,txt$:表示搜索text以tag结尾的控件,txt^:表示搜索text以tag开始的控件,txt*:表示搜索text包含tag的控件。clickPosition表示点击的目标位置信息,可以为[left, top]或者[left, top, width, height]。 |
checkTag | string | 必填 | 目标页面的tag,注意只能为text,多个文本使用|连接,找到任意一个即可,txt:表示精确搜索text为tag的控件,txt$:表示搜索text以tag结尾的控件,txt^:表示搜索text以tag开始的控件,txt*:表示搜索text包含tag的控件。例:'txt:我的|txt:首页'。 |
options | json object | {findRegion:null, checkRegion:null, showOcrResult: false, clickMode:1, duration:500, maxStep:5, maxCheckStep:1, random: false, beforeWait:0, afterWait:0, failed: null, timeout: 1000, online:null,findAwesome:{threshold: 0.1, count:3}, checkAwesome:{threshold: 0.1, count:3}} | findRegion和checkRegion可以在ocr时指定区域[left, top, width, height],注意:若取值在[0, 1]之间表示比例,例:[0.5, 100, 100, 200]表示left位于屏幕x轴中点;若取值大于1表示像素值。showOcrResult表示是否在log中显示ocr的结果,用于调试。duration表示两次搜索的间隔时间,单位毫秒。maxStep表示当搜索失败时,重搜索的最大次数。maxCheckStep表示一次搜索时最多检查几次目标tag。beforeWait表示在搜索前等待的时间,单位毫秒。afterWait表示在搜索完成后等待的时间,单位毫秒。failed表示搜索控件失败后调用的函数,主要用于在操作期间出现弹窗的场景。timeout指ocr的超时时间,默认1000毫秒。注意:如果failed返回true则会立即检查2次是否到达目标页面。 online表示使用在线识别,比如:{url:'http://abc.com/api', key:'', secret:''},url表示服务器url,key和secret为可选鉴权参数。findAwesome:{threshold:0.9, count: 3},threshold取值范围[0.5, 0.9], count取值范围[2, 6]。checkAwesome:{threshold:0.9, count: 3},threshold取值范围[0.5, 0.9], count取值范围[2, 6]。clickMode表示点击模式,1表示无障碍,2表示蓝牙,3表示usb,4表示root,5表示adb,如果使用蓝牙、usb、adb则需要先调用相应的初始化函数。 |
例子: function main() { requestScreenShot(); var ret = ocrBack2Page('首页'); console.log('ret:' + ret); }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
tag | string | 必填 | tag,表示目标页面中的tag文本,注意只能为text,txt:表示精确搜索text为tag的控件,txt$:表示搜索text以tag结尾的控件,txt^:表示搜索text以tag开始的控件,txt*:表示搜索text包含tag的控件。 |
options | json object | {midTag:'', backMode: 1, region:null, backFirst: true, duration:1000, maxStep:5, maxCheckStep:2, beforeWait:0, afterWait:0, failed: null, timeout:1000, online:null, awesome:{threshold: 0.1, count:3}} | midTag表示在返回目标页面过程中的中间页面上的唯一tag。backFirst表示是否先模拟点击返回按键。region可以在ocr时指定区域[left, top, width, height],注意:若取值在[0, 1]之间表示比例,例:[0.5, 100, 100, 200]表示left位于屏幕x轴中点;若取值大于1表示像素值。duration表示两次搜索的间隔时间,单位毫秒。maxStep表示当搜索失败时,重搜索的最大次数。maxCheckStep表示一次搜索时最多检查几次目标tag。beforeWait表示在搜索前等待的时间,单位毫秒。afterWait表示在搜索完成后等待的时间,单位毫秒。failed表示搜索控件失败后调用的函数,主要用于在操作期间出现弹窗的场景。timeout指ocr的超时时间,默认1000毫秒。online表示使用在线识别,比如:{url:'http://abc.com/api', key:'', secret:''},url表示服务器url,key和secret为可选鉴权参数。awesome:{threshold:0.9, count: 3},threshold取值范围[0.5, 0.9], count取值范围[2, 6]。backMode表示使用什么方法按返回键,1表示无障碍,2表示蓝牙,3表示usb,4表示root,5表示adb,如果使用蓝牙、usb、adb则需要先调用相应的初始化函数。 |