【人像特效】营业执照识别
才能我浪费99 发布于2020-12 浏览:3856 回复:0
0
收藏
最后编辑于2022-04

1.功能描述:

可结构化识别各类版式的营业执照,返回证件编号、社会信用代码、单位名称、地址、法人、类型、成立日期、有效日期、经营范围等关键字段信息

2.平台接入

具体接入方式比较简单,可以参考我的另一个帖子,这里就不重复了:
http://ai.baidu.com/forum/topic/show/943327

3.调用攻略(Python3)及评测

3.1首先认证授权:

在开始调用任何API之前需要先进行认证授权,具体的说明请参考:

http://ai.baidu.com/docs#/Auth/top

具体Python3代码如下:

# -*- coding: utf-8 -*-
#!/usr/bin/env python

import urllib
import base64
import json
#client_id 为官网获取的AK, client_secret 为官网获取的SK
client_id =【百度云应用的AK】
client_secret =【百度云应用的SK】

#获取token
def get_token():
    host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret
    request = urllib.request.Request(host)
    request.add_header('Content-Type', 'application/json; charset=UTF-8')
    response = urllib.request.urlopen(request)
    token_content = response.read()
    if token_content:
        token_info = json.loads(token_content)
        token_key = token_info['access_token']
    return token_key


3.2接口调用:

详细说明请参考: https://ai.baidu.com/ai-doc/OCR/sk3h7y3zs

说明的比较清晰,这里就不重复了。

大家需要注意的是:
API访问URL:https://aip.baidubce.com/rest/2.0/ocr/v1/business_license

输入参数image和url二选一:
image:图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式
url:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式,当image字段存在时url字段失效。请注意关闭URL防盗链

返回示例
{
"log_id": 490058765,
"words_result": {
"社会信用代码": {
"words": "10440119MA06M8503",
"location": {
"top": 296,
"left": 237,
"width": 178,
"height": 18
}
},
"组成形式": {
"words": "无",
"location": {
"top": -1,
"left": -1,
"width": 0,
"height": 0
}
},
"经营范围": {
"words": "商务服务业",
"location": {
"top": 587,
"left": 378,
"width": 91,
"height": 18
}
},
"成立日期": {
"words": "2019年01月01日",
"location": {
"top": 482,
"left": 1045,
"width": 119,
"height": 19
}
},
"法人": {
"words": "方平",
"location": {
"top": 534,
"left": 377,
"width": 39,
"height": 19
}
},
"注册资本": {
"words": "200万元",
"location": {
"top": 429,
"left": 1043,
"width": 150,
"height": 19
}
},
"证件编号": {
"words": "921MA190538210301",
"location": {
"top": 216,
"left": 298,
"width": 146,
"height": 16
}
},
"地址": {
"words": "广州市",
"location": {
"top": 585,
"left": 1041,
"width": 55,
"height": 19
}
},
"单位名称": {
"words": "有限公司",
"location": {
"top": 429,
"left": 382,
"width": 72,
"height": 19
}
},
"有效期": {
"words": "长期",
"location": {
"top": 534,
"left": 1045,
"width": 0,
"height": 0
}
},
"类型": {
"words": "有限责任公司(自然人投资或控股)",
"location": {
"top": 482,
"left": 382,
"width": 260,
"height": 18
}
}
},
"log_id": 1310106134421438464,
"words_result_num": 11
}

Python3调用代码如下:

#调用百度营业执照识别接口
def business_license(filename):
    request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license"
    
    # 二进制方式打开图片文件
    f = open(filename, 'rb')
    img = base64.b64encode(f.read())
    
    params = dict()
    params['image'] = img
    params = urllib.parse.urlencode(params).encode("utf-8")
    
    access_token = get_token()
    
    begin = time.perf_counter()
    request_url = request_url + "?access_token=" + access_token
    request = urllib.request.Request(url=request_url, data=params)
    request.add_header('Content-Type', 'application/x-www-form-urlencoded')
    response = urllib.request.urlopen(request)
    content = response.read()
    end = time.perf_counter()

    print('处理时长:'+'%.2f'%(end-begin)+'秒')
    
    if content:
        #print(content)
        content=content.decode('utf-8')
        #print(content)
        data = json.loads(content)
        #print(data)
        words_result=data['words_result']
        print ("识别结果")
        for item in words_result:
            print (item,':',words_result[item]['words'])



4.功能评测(图片来自网络):

具体效果如下:

处理时长:4.97秒
识别结果
社会信用代码 : 10440119MA06M8503
组成形式 : 无
经营范围 : 商务服务业
成立日期 : 2019年01月01日

...

类型 : 有限责任公司(自然人投资或控股)

5.测试结论和建议

测试下来,整体识别效果不错。营业执照的很准确,速度也很快,用起来非常的方便。可以用于:
商家资质审查
结构化识别录入企业信息,应用于电商、零售、O2O等行业的商户入驻审查场景,实现商户信息的自动化审查和录入,大幅度提升服务标准和运营效率
企业金融服务
自动识别录入企业信息,应用于企业银行开户、抵押贷款等金融服务场景,大幅度提升信息录入效率,并有效控制业务风险

收藏
点赞
0
个赞
TOP
切换版块