调用百度的车牌识别api

用于数据标注,一天200次以内是免费的。

1. 获取access_token

在百度大脑上新建应用,在管理应用中获得API Key和Secret Key,得到access_token
调用百度的车牌识别api_第1张图片
修改以下的对应位置,获得access_token.

# import requests 
# # client_id 为官网获取的AK, client_secret 为官网获取的SK
# host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=,,,,,,,,,&client_secret=,,,,,,,,,,'
# response = requests.get(host)
# if response:
#     print(response.json()['access_token'])

2. 调用api

替换对应应用api和access_token.

import requests
import base64
'''
OCR 通用识别
'''
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate"
# 二进制方式打开图片文件
f = open('./dataset/images/─■A0C93F.jpg', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
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:
    print (response.json())

输出内容:
{‘log_id’: 93069774819587722, ‘words_result’: {‘color’: ‘blue’, ‘number’: ‘宁A0C93F’, ‘probability’: [0.9195201396942139, 0.9013998508453369, 0.9016464352607727, 0.901291012763977, 0.9018189311027527, 0.9011477828025818, 0.9013288021087646], ‘vertexes_location’: [{‘y’: 835, ‘x’: 570}, {‘y’: 834, ‘x’: 746}, {‘y’: 881, ‘x’: 746}, {‘y’: 882, ‘x’: 570}]}}


测试图片

调用百度的车牌识别api_第2张图片

调用百度的车牌识别api_第3张图片
输出:
{‘log_id’: 6488303799225047914, ‘words_result’: {‘color’: ‘yellow’, ‘number’: ‘粤J33333’, ‘probability’: [0.9009954333305359, 0.9064544439315796, 0.9030976295471191, 0.9082970023155212, 0.9020709991455078, 0.9015403389930725, 0.9015218615531921], ‘vertexes_location’: [{‘y’: 342, ‘x’: 273}, {‘y’: 343, ‘x’: 363}, {‘y’: 385, ‘x’: 363}, {‘y’: 384, ‘x’: 273}]}}

能识别双层车牌。

你可能感兴趣的:(ocr,baiduapi)