Baidu AI characters get identity cards (simple version)

Base64 Import 
Import Requests
AK # client_id official network acquired, client_secret official net acquisition of SK
Host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【AK】&client_secret=【SK]'
= {headers 'the Type-the Content': 'file application / JSON; charset = UTF-. 8'}
Response = requests.post (= Host URL, headers = headers)
CON = response.json ()
the access_token = CON [ 'the access_token']
= URL 'https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=' + the access_token
# file opened in binary mode FIG
f = open (r 'identity .jpg', 'rb')
# parameters image: base64 encoded image
IMG = base64.b64encode (reached, f.read ())
the params = { "image": IMG, "id_card_side": "Front"}
headers = { 'Content-Type':'application/x-www-form-urlencoded'}
respones = requests.post(url=url,data=params,headers=headers)
content = respones.json()
if content:
print(content)

Guess you like

Origin www.cnblogs.com/xiaoxiaoxl/p/11203193.html