身份证号码识别(python)

使用的百度开放api .

import requests
import base64
import json
 
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard"
# 二进制方式打开图片文件
f = open('本地图片地址', 'rb')
image = base64.b64encode(f.read())

params = {"id_card_side": "front", "image": image}
access_token = '改成你自己的access_token'

request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)

if response:
    name = json.loads(response.text)['words_result']['姓名']['words']
    address = json.loads(response.text)['words_result']['住址']['words']
    birth = json.loads(response.text)['words_result']['出生']['words']
    id = json.loads(response.text)['words_result']['公民身份号码']['words']
    sex = json.loads(response.text)['words_result']['性别']['words']
    minzu = json.loads(response.text)['words_result']['民族']['words']
 
    
    print('正在识别中')
    print('姓名:', name, '性别:', sex, '住址:', address, '身份证号:', id, '出生年月:', birth, '民族:', minzu)
if response:
    print('已经识别成功')

然后是access_token的获取

 

import requests
import json
 
url = "https://aip.baidubce.com/oauth/2.0/token"
 
data = {
    'grant_type': 'client_credentials',
    'client_id': ''改成你自己的id',
    'client_secret': '改成你自己的secret',
}
 
response = requests.post(url=url, data=data)
data2 = json.loads(response.text) 
accesstoken = data2['access_token']

api在百度智能云-产品-人工智能-图像识别就可以申请

然后创建应用就行了

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值