利用百度AI 识别图片上的文字 2身份证的识别

# python百度ai的身份证识别代码
# -*- coding: UTF-8 -*-
from aip import AipOcr

# 定义常量
APP_ID = '20225407'
API_KEY = 'zWGe7eiBpxqK3DXCRGW7hg1h'
SECRET_KEY = 'Ch3VXkshTVOLICUYIY2vkvOAOnacPQRa'

# 初始化AipFace对象
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

# 读取图片


def get_file_content(filepath):
    with open(filepath, 'rb') as fp:
        return fp.read()


image = get_file_content('C:\\Users\\JiaShuo\\Desktop\\001\\200.jpg')
idCardSide = "front"
print(type(image))
""" 调用身份证识别 """
result = client.idcard(image, idCardSide)


print("姓名:", result["words_result"]["姓名"]["words"])
print("性别:", result["words_result"]["性别"]["words"])
print("民族:", result["words_result"]["民族"]["words"])
print("生日:", result["words_result"]["出生"]["words"])
print("身份证号:", result["words_result"]["公民身份号码"]["words"])
print("住址:", result["words_result"]["住址"]["words"])

你可能感兴趣的:(利用百度AI 识别图片上的文字 2身份证的识别)