Python uses Ali API for ID card identification

1. Introduction of the author

Meng Liping, female, School of Electronic Information, Xi'an Polytechnic University, 2021 master student, Zhang Hongwei's artificial intelligence research group
Research direction: machine vision and artificial intelligence
Email: [email protected]

2. Introduction to ID card identification

With the leading artificial intelligence and knowledge graph technology, it automatically recognizes the front and back of the ID card, and extracts the ID card entity information such as name, date of birth, ID number, address, gender, ethnicity, and issuing authority.

3. Call Alibaba Smart Cloud API

Step 1 : Search Alibaba Cloud with your browser, use Alipay or other Ali APP to scan the code and log in with the verification code on your mobile phone.
insert image description here

Step 2 : After logging in, find the ID card to identify the OCR product and purchase it
insert image description here

Step 3 : Click on the management console after the purchase is successful
insert image description here

Step 4 : Check the AppCode and other information for ID card identification
insert image description here
Step 5 : Check the Python implementation code, and replace the appcode in the code with your own appcode
insert image description here
Step 6 : Check the request parameters, calling the API needs to provide the ID number and ID number in the code Name, no need to upload ID card picture
insert image description here
Step 7 : After running the code, the return value includes whether the real-name authentication is passed, ID number, name, home address and date of birth, etc.
insert image description here

4. Code analysis

4.1 Complete code

# coding=UTF-8
import requests
host = 'https://idcert.market.alicloudapi.com'
path = '/idcard'
method = 'GET'
appcode = '你自己的AppCode'#开通服务后 买家中心-查看AppCode
querys = 'idCard=511126******064713&name=杨过'
bodys = {
    
    }
url = host + path + '?' + querys
header = {
    
    "Authorization":'APPCODE ' + appcode}
try:
    res = requests.get(url,headers=header)
except :
    print("URL错误")
    exit()
httpStatusCode = res.status_code

if(httpStatusCode == 200):
    print("正常请求计费(其他均不计费)")
    print(res.text)
else:
    httpReason = res.headers['X-Ca-Error-Message']
    if(httpStatusCode == 400 and httpReason == 'Invalid Param Location'):
        print("参数错误")
    elif(httpStatusCode == 400 and httpReason == 'Invalid AppCode'):
        print("AppCode错误")
    elif(httpStatusCode == 400 and httpReason == 'Invalid Url'):
        print("请求的 Method、Path 或者环境错误")
    elif(httpStatusCode == 403 and httpReason == 'Unauthorized'):
        print("服务未被授权(或URL和Path不正确)")
    elif(httpStatusCode == 403 and httpReason == 'Quota Exhausted'):
        print("套餐包次数用完")
    elif(httpStatusCode == 403 and httpReason == 'Api Market Subscription quota exhausted'):
        print("套餐包次数用完,请续购套餐")
    elif(httpStatusCode == 500 ):
        print("API网关错误")
    else:
        print("参数名错误 或 其他错误")
        print(httpStatusCode)
        print(httpReason)

4.2 Experimental results

insert image description here

reference

1. Directly jump to the link to purchase Aliyun’s ID card recognition OCR link:
https://market.aliyun.com/products/57000002/cmapi022049.html?spm=5176.shop.result.7.41a272026nu6Gi&innerSource=search#sku=yuncode1604900000

Guess you like

Origin blog.csdn.net/m0_37758063/article/details/123825323