身份证识别系统(RecognizeIdentityCard)是阿里云视觉系统中提供的一个服务,通过扫描身份证照片来得到图片上的文本信息,并返回给用户。在互联网时代,这项服务无疑为个人信息识别提供了很大的方便。
示例
这个api会返回一个json文件,记录了身份证上的各个信息
"RequestId": "F60CC98C-B8E9-4288-839E-2C4A201FEEA4",
"Data": {
"FrontResult": {
"Address": "杭州市西湖区万塘路黄龙时代广场",
"FaceRectVertices": [
{
"X": "338.63800048828125",
"Y": "190.12008666992188"
},
{
"X": "337.53411865234375",
"Y": "117.78894805908203"
},
{
"X": "403.37005615234375",
"Y": 116.7841796875
},
{
"X": "404.47393798828125",
"Y": "189.11532592773438"
}
],
"FaceRectangle": {
"Center": {
"X": "371.0040283203125",
"Y": "153.45213317871094"
},
"Angle": "-0.8743622899055481",
"Size": {
"Height": "72.339553833007812",
"Width": "65.843612670898438"
}
},
"CardAreas": [
{
"X": 62,
"Y": 64
},
{
"X": 456,
"Y": 60
},
{
"X": 459,
"Y": 281
},
{
"X": 65,
"Y": 286
}
],
"Gender": "女",
"Nationality": "汉",
"Name": "支小宝",
"IDNumber": "330106200503287127",
"BirthDate": "20050326"
}
}
}
那么,如何调用这个强大的api呢?
阿里云视觉开发中心
选择 能力广场-文字识别-身份证识别 选项,体验身份证识别的功能。
官方提供了调用这个api的文档:
身份证识别官方文档
1、开通身份证识别
身份证识别首页
2、开通oss服务
对象存储服务(Object Storage Service,OSS)是一种海量、安全、低成本、高可靠的云存储服务,适合存放任意类型的文件。容量和处理能力弹性扩展,多种存储类型供选择,全面优化存储成本。
阿里云对象存储服务
3、使用python SDK 调用API
推荐使用python3.6版本
#!/usr/bin/env python
#coding=utf-8
import oss2
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkocr.request.v20191230.RecognizeIdentityCardRequest import RecognizeIdentityCardRequest
import json
info = open('myinfo.json','r')
_json = json.load(info)
info.close()
auth = oss2.Auth(_json['accesskey'], _json['secret'])
bucket = oss2.Bucket(auth,'http://oss-cn-shanghai.aliyuncs.com','current-cloud-oss')
bucket.create_bucket(oss2.models.BUCKET_ACL_PRIVATE)
try:
bucket.put_object_from_file('identCard/sfz.jpg', 'sfz.jpg')
except Exception as e:
print(e)
exit()
client = AcsClient(_json['accesskey'], _json['secret'], 'cn-shanghai')
request = RecognizeIdentityCardRequest()
request.set_accept_format('json')
request.set_ImageURL("https://bucket.oss-cn-shanghai.aliyuncs.com/identCard/sfz.jpg?Content-Typr=image/jpeg")
request.set_Side("face")
response = client.do_action_with_exception(request)
print(str(response, encoding='utf-8'))
通过对象存储sdk将图片上传到oss中,再通过调用身份证识别方法来获取信息,再辅以pyside,pyqt等GUI来实现窗口化交互。