阅读(4860) (0)

百度智能小程序 识别机动车驾驶证

2020-08-13 15:58:49 更新

swan.ai.ocrDrivingLicense

解释:对机动车驾驶证所有关键字段进行识别。

方法参数

Object object

object 参数说明

属性名 类型 必填 默认值 说明

image

String

-

图像资源地址

detect_direction

Boolean

是否检测图像旋转,可检验图像的选装方向和旋转角度。
· true:检测旋转角度并矫正识别。针对摆放情况不可控制的情况建议本参数置为 true;
· false:不检测旋转角度,默认不检测。

unified_valid_period

Boolean


· true:归一化格式输出;
· false 或无此参数按非归一化格式输出。

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明

参数 类型 说明

log_id

Number

唯一的 log id,用于问题定位。

words_result_num

Number

识别结果数,表示 words_result 的元素个数。

words_result

Object

识别结果

words_result 返回值说明

参数名 参数类型 说明
证号 Object 证号(持证人的身份证号)
有效期限 Object 有效期限
准驾车型 Object 准驾车型
有效起始日期 Object 有效起始日期
住址 Object 住址
姓名 Object 姓名
国籍 Object 国籍
出生日期 Object 出生日期
性别 Object 性别
初次领证日期 Object 初次领证日期

证号/有效期限/准驾车型/有效起始日期/住址/姓名/国籍/出生日期/性别/初次领证日期 返回值说明

参数名 参数类型 说明
words String 识别结果字符串

示例 

在开发者工具中打开



图片示例



代码示例

Page({
    ocrDrivingLicense() {
        swan.chooseImage({
            success: res => {
                let image = res.tempFilePaths[0];
                // AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误
                let host = swan.getSystemInfoSync().host;
                if (host === 'baiduboxapp') {
                    swan.ai.ocrDrivingLicense({
                        image, // 暂不支持识别网络图片
                        detect_direction: true,
                        unified_valid_period: true,
                        success: res => {
                            console.log('ocrDrivingLicense res',res.words_result);
                        },
                        fail: err => {
                            console.log('ocrDrivingLicense err', err);
                        }
                    });
                }
                else {
                    swan.showToast({
                        title: '此api目前仅可在百度App上使用',
                        icon: 'none'
                    });
                }
            }
        })
    }
});

返回值示例

{
    "log_id": $log_id,
    "direction": -1,
    "words_result_num": 10,
    "words_result": {
        "证号": {
            "words": "3208231999053090"
        },
        "有效期限": {
            "words": "6年"
        },
        "准驾车型": {
            "words": "B2"
        },
        "有效起始日期": {
            "words": "20101125"
        },
        "住址": {
            "words": "江苏省南通市海门镇秀山新城"
        },
        "姓名": {
            "words": "小欧欧"
        },
        "国籍": {
            "words": "中国"
        },
        "出生日期": {
            "words": "19990530"
        },
        "性别": {
            "words": "男"
        },
        "初次领证日期": {
            "words": "20100125"
        }
    }
}