例子: function main() { requestScreenShot(); var ret = ocr({region:[100, 100, 200, 130]}); console.log('ret:' + ret); }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
options | object | 选填,默认值:{region:[0, 0, 1, 1], bitmap: 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则使用截屏后图片,否则直接使用该位图。如果感觉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); }
var key = '', secret = ''; function main() { requestScreenShot(); // 从自定义数据中获取key。您需要去冰狐官网创建自定义数据并填入key key = getCustomData('custom_data_key') // 从自定义数据中获取secret。您需要去冰狐官网创建自定义数据并填入secret secret = getCustomData('custom_data_secret') var ocrResult = screenShot(cbDealImage) console.log('ocrResult:', ocrResult) } // 截屏处理函数,data为截屏后的png数据 function cbDealImage(data) { var r = base64Encode(data) // 注意这里不需要调用urlEncode,因为httpPost默认会自动调用urlEncode var ret = httpPost('https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + key '&client_secret=' + secret, null, {"Content-Type":"application/json", "Accept":"application/json"}) if (ret.state == "success") { var data = JSON.parse(ret.data); var token = data.access_token; console.log('token:', token) var ret = httpPost('https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=' + token, {image:r}, {"Content-Type":"application/x-www-form-urlencoded"}) console.log('req:', ret) if (ret.state == 'success') { var data = JSON.parse(ret.data) var result = data.words_result; console.log('data:', result) return result; } } return null; }
例子: 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, 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毫秒。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, 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毫秒。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, 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次是否到达目标页面。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, 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毫秒。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则需要先调用相应的初始化函数。 |