Skip to content

Instantly share code, notes, and snippets.

@YKalashnikov
Created February 27, 2020 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YKalashnikov/8617a1f2755270fae77180a33f63e5c0 to your computer and use it in GitHub Desktop.
Save YKalashnikov/8617a1f2755270fae77180a33f63e5c0 to your computer and use it in GitHub Desktop.
import base64
import requests
image_path = 'YOUR_IMAGE_PATH'
secret_key = 'YOUR_SECRET_KEY'
with open(image_path, 'rb') as image_file:
img_base64 = base64.b64encode(image_file.read())
url = 'https://api.openalpr.com/v2/recognize_bytes'+'?recognize_vehicle=1&country=ru&secret_key={}'.format(secret_key)
r = requests.post(url, data = img_base64)
try:
print({
'Plate': r.json()['results'][0]['plate'],
'Region': r.json()['results'][0]['region'],
'Brand': r.json()['results'][0]['vehicle']['make'][0]['name'],
'Color': r.json()['results'][0]['vehicle']['color'][0]['name'],
'Year': r.json()['results'][0]['vehicle']['year'][0]['name']
})
except:
print ('oops plate cannot be identified ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment