百度智能小程序 用戶向服務(wù)請(qǐng)求識(shí)別身份證

2020-09-05 14:15 更新

swan.ai.ocrIdCard

解釋:用戶向服務(wù)請(qǐng)求識(shí)別身份證,身份證識(shí)別包括正面和背面。

方法參數(shù)

Object object

object 參數(shù)說明

屬性名 類型 必填 默認(rèn)值 說明

detect_direction

Boolean

是否檢測(cè)圖像旋轉(zhuǎn),可檢驗(yàn)圖像的旋轉(zhuǎn)方向和旋轉(zhuǎn)角度。
· true:檢測(cè)旋轉(zhuǎn)角度并矯正識(shí)別。針對(duì)擺放情況不可控制的情況建議本參數(shù)置為 true ;
· false:不檢測(cè)旋轉(zhuǎn)角度,默認(rèn)不檢測(cè)。

id_card_side

String

-

front:身份證含照片的一面;back:身份證帶國徽的一面。

image

String

圖片資源地址

detect_risk

Boolean

-

是否開啟身份證風(fēng)險(xiǎn)類型(身份證復(fù)印件、臨時(shí)身份證、身份證翻拍、修改過的身份證)功能,默認(rèn)不開啟,即:false 。有效值:true-開啟;false-不開啟。

success

Function

接口調(diào)用成功的回調(diào)函數(shù)

fail

Function

接口調(diào)用失敗的回調(diào)函數(shù)

complete

Function

接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)

success 返回參數(shù)說明

參數(shù) 類型 說明

direction

Number

圖像方向,當(dāng) detect_direction=true 時(shí)存在。-1:未定義,0:正向,1:逆時(shí)針 90 度,2:逆時(shí)針 180 度,3:逆時(shí)針 270 度。

image_status

String

normal-識(shí)別正常;reversed_side-身份證正反面顛倒;non_idcard-上傳的圖片中不包含身份證;blurred-身份證模糊;other_type_card-其他類型證照;over_exposure-身份證關(guān)鍵字段反光或過曝;unknown-未知狀態(tài)。

risk_type

String

輸入?yún)?shù) detect_risk = true 時(shí),則返回該字段識(shí)別身份證類型:normal-正常身份證;copy-復(fù)印件;temporary-臨時(shí)身份證;screen-翻拍;unknown-其他未知情況。

edit_tool

String

如果參數(shù) detect_risk = true 時(shí),則返回此字段。如果檢測(cè)身份證被編輯過,該字段指定編輯軟件名稱,如:Adobe Photoshop CC 2014 (Macintosh),如果沒有被編輯過則返回值無此參數(shù)。

log_id

Number

唯一的 log id ,用于問題定位。

words_result_num

Number

識(shí)別結(jié)果數(shù),表示 words_result 的元素個(gè)數(shù)。

words_result

Object

定位和識(shí)別結(jié)果

words_result 返回值說明

參數(shù)名 參數(shù)類型 說明

住址

Object

住址

公民身份號(hào)碼

Object

公民身份號(hào)碼

出生

Object

出生

姓名

Object

姓名

性別

Object

性別

民族

Object

民族

住址/公民身份號(hào)碼/出生/姓名/性別/民族 返回值說明

參數(shù)名 參數(shù)類型 說明

location

Object

位置信息(坐標(biāo) 0 點(diǎn)為左上角)

words

String

識(shí)別結(jié)果字符串

location 返回值說明

參數(shù)名 參數(shù)類型 說明

left

Number

表示識(shí)別結(jié)果的定位位置的長(zhǎng)方形左上頂點(diǎn)的水平坐標(biāo)。

top

Number

表示識(shí)別結(jié)果的定位位置的長(zhǎng)方形左上頂點(diǎn)的垂直坐標(biāo)。

width

Number

表示識(shí)別結(jié)果的定位位置的長(zhǎng)方形的寬度。

height

Number

表示識(shí)別結(jié)果的定位位置的長(zhǎng)方形的高度。

示例



圖片示例



代碼示例 

在開發(fā)者工具中打開

Page({
    ocrIdCard() {
        swan.chooseImage({
            success: res => {
                let image = res.tempFilePaths[0];
                // AI系列的api有宿主使用限制,只可在百度App中使用,建議使用時(shí)加一層判斷防止代碼報(bào)未知錯(cuò)誤
                let host = swan.getSystemInfoSync().host;
                if (host === 'baiduboxapp') {
                    swan.ai.ocrIdCard({
                        detect_direction: true,
                        id_card_side: 'front',
                        image, // 暫不支持識(shí)別網(wǎng)絡(luò)圖片
                        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": "南京市江寧區(qū)弘景大道3889號(hào)"
        },
        "公民身份號(hào)碼": {
            "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
}


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)