Python调用百度API识别车牌号, 修改成自己的试试
client_id
client_secret
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "leo"
__time__ = "2018-09-09"
import base64
import requests
def get_token():
get_token_url = "https://aip.baidubce.com/oauth/2.0/token"
params = {
"grant_type": "client_credentials",
"client_id": "xxx",
"client_secret": "xxxxx",
}
res = requests.get(get_token_url, params).json()
return res["access_token"]
if __name__ == '__main__':
access_token = get_token()
url = "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate"
with open("car.jpeg", mode='rb')as f:
image = base64.b64encode(f.read())
# image =
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
data = {
"access_token": access_token,
"image": image
}
res = requests.post(url, headers=headers, data=data).json()["words_result"]
print(res["number"])