首页 身份证识别 身份证识别示例代码 身份证识别[Python]

身份证识别示例代码[Python]

作者:liuxiaojie 阅读数:3815 上传时间:2016-03-10

身份证识别

#!/usr/bin/python
# encoding:utf-8

import urllib2, json, urllib, cookielib
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers


# 2、证件识别

data = {}
data["appkey"] = "your_appkey_here"
data["typeid"] = 2
register_openers()
datagen, headers = multipart_encode({"pic": open("11.jpg", "rb")})

url_values = urllib.urlencode(data)
url = "https://api.jisuapi.com/idcardrecognition/recognize" + "?" + url_values

request = urllib2.Request(url,datagen, headers)
result = urllib2.urlopen(request)
jsonarr = json.loads(result.read())

if jsonarr["status"] != u"0":
    print jsonarr["msg"]
    exit()
result = jsonarr["result"]

for v in result:
    print v,result[v]