Skip to content

Instantly share code, notes, and snippets.

@leo493852107
Last active October 27, 2019 06:13
Show Gist options
  • Save leo493852107/db24c24f22eb98a125f8d844596d0327 to your computer and use it in GitHub Desktop.
Save leo493852107/db24c24f22eb98a125f8d844596d0327 to your computer and use it in GitHub Desktop.
Python调用百度API识别车牌号
#!/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": "9tCB6nCKK1e3ExUMjrjnOS83",
"client_secret": "mRwkOwE2NXPeli2ccV15EQaQFYwLRDWo",
}
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("IMG_8018.JPG", 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()
if "error_code" in res:
print(res["error_msg"])
else:
words_result = res["words_result"]
print(words_result["number"])
@Wdam
Copy link

Wdam commented Apr 28, 2019

我也在做这个项目,用opencv,但遇到一些问题,opencv处理过的帧图片我不知道怎么传给百度api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment