swan.ai.ocrIdCard
解释:用户向服务请求识别身份证,身份证识别包括正面和背面。
方法参数
Object object
object参数说明
success 返回参数说明
words_result 返回值说明
住址/公民身份号码/出生/姓名/性别/民族 返回值说明
location 返回值说明
示例
请使用百度APP扫码
图片示例
代码示例:
在开发者工具中预览效果
Page({ ocrIdCard() { swan.chooseImage({ success: res => { let image = res.tempFilePaths[0]; // AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误 let host = swan.getSystemInfoSync().host; if (host === 'baiduboxapp') { swan.ai.ocrIdCard({ detect_direction: true, id_card_side: 'front', image, // 暂不支持识别网络图片 detect_risk: true, success: res => { console.log('ocrIdCard res', res.words_result); }, fail: err => { console.log('ocrIdCard err', err); } }); } else { swan.showToast({ title: '此api目前仅可在百度App上使用', icon: 'none' }); } } }) }});
返回值示例 :
{ "log_id": $log_id, "direction": 0, "image_status": "normal", "idcard_type": "normal", "edit_tool": "Adobe Photoshop CS3 Windows", "words_result": { "住址": { "location": { "left": 267, "top": 453, "width": 459, "height": 99 }, "words": "南京市江宁区弘景大道3889号" }, "公民身份号码": { "location": { "left": 443, "top": 681, "width": 589, "height": 45 }, "words": "330881199904173914" }, "出生": { "location": { "left": 270, "top": 355, "width": 357, "height": 45 }, "words": "19990417" }, "姓名": { "location": { "left": 267, "top": 176, "width": 152, "height": 50 }, "words": "伍云龙" }, "性别": { "location": { "left": 269, "top": 262, "width": 33, "height": 52 }, "words": "男" }, "民族": { "location": { "left": 492, "top": 279, "width": 30, "height": 37 }, "words": "汉" } }, "words_result_num": 6}
