1 介绍
利用Face++的API进行工作,可以根据身份证信息识别出文字信息。
注:此API目前免费使用。
2 程序
1 import requests 2 from json import JSONDecoder 3 import datetime 4 5 http_url ="https://api-cn.faceplusplus.com/cardpp/v1/ocridcard" 6 key ="申请的ID" 7 secret ="申请的密钥" 8 imgpath =r'图片路径' 9 10 data = {"api_key":key, "api_secret": secret, "legality": 0} 11 files = {"image_file": open(imgpath, "rb")} 12 response = requests.post(http_url, data=data, files=files) 13 req_con = response.content.decode('utf-8') 14 req_dict = JSONDecoder().decode(req_con) 15 # print(req_dict) 16 people_message = req_dict['cards'][0] #不加[0]的话,返回的是列表内有一个字典,形式为[{}],加入[0],则是一个字典 17 # print(people_message) 18 print('姓名:',people_message['name']) 19 print('性别:',people_message['gender']) 20 print('民族:',people_message['race']) 21 print('生日:',people_message['birthday']) 22 print('身份证号:',people_message['id_card_number']) 23 print('地址:',people_message['address'])