文字识别(含位置信息高精度版)
[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.bdrecognition.accurate(success, error,options)
支持平台:
- Android
- iOS
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
success | Function | 是 | 成功回调函数 |
error | Function | 是 | 失败回调函数 |
options | Object | 是 | 数据对象 |
success
函数会返回一个json字符串,识别数据扫描结果信息:
result
(对象) -- 文字识别返回的所有数据,数据参考:https://ai.baidu.com/docs#/OCR-API/9fee3cfemessage
(对象) -- 文字识别数据,其属性包含以下一项或多项:message
(String) -- 识别的文字imagePath
(String) -- 扫描的图片存储路径
error
函数会返回一个字符串,扫描错误的相关信息,错误码参考https://ai.baidu.com/docs#/OCR-API/58fd45dd
options
参数为一个对象,其属性包含以下一项或多项:
imgPath
(Int/ 可选) -- 扫描的图片存储路径,0:相册,1:项目路径,默认相册imgType
(Int/ 可选) -- 扫描的图片类型,0:.jpg格式,1:.png格式,默认jpg
示例代码
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
navigator.bdrecognition.accurate(function (success) {
alert(success);
},function (error) {
alert(error);
},{'imgPath':0,'imgType':0});
}
</script>
响应示例代码:
{
"result": {
"log_id": 4032129901991346700,
"words_result_num": 1,
"words_result": [
{
"words": "运行日志",
"location": {
"top": 107,
"width": 163,
"left": 0,
"height": 40
}
}
],
"direction": 0
},
"message": {
"message": "运行日志",
"imagePath": "cdvfile://localhost/assets-library/asset/asset.JPG?id=7D51D33A-6AAC-4E60-AB6C-97D8FDD32488&ext=JPG"
}
}