-
Notifications
You must be signed in to change notification settings - Fork 0
/
getNumberPlateVals.py
48 lines (40 loc) · 1.53 KB
/
getNumberPlateVals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import base64
import requests
import json
import re
url = 'https://vision.googleapis.com/v1/images:annotate?key=Your_Api_Key'
def detect_license_plate(encodedImage):
# img_base64 = base64.b64encode(imagePath)
headers = {'content-type': 'application/json'}
data = """{
"requests": [
{
"image": {
"content": '""" + encodedImage[:-1] + """'
},
"features": [
{
"type": "TEXT_DETECTION"
}
]
}
]
}"""
r = requests.post(url, headers=headers, data=data)
result = json.loads(r.text)
print(result)
try:
result = result['responses'][0]['textAnnotations'][0]['description']
except Exception as e:
return r
result = result.replace('\n', '').replace(' ', '')
result =re.sub('\W+','', result)
mystates = ['AP','AR','AS','BR','CG','GA','GJ','HR' ,'HP' ,'JK','JH','KA','KL','MP','MH','MN','ML','MZ','NL' ,'OD','PB' ,'RJ','SK','TN','TS','TR','UA','UK','UP','WB','AN','CH','DN','DD','DL' ,'LD','PY']
if(len(result) > 0):
#res=re.findall("\s*[AP,AR,AS,BR,CG,GA,GJ,HR,HP,JK,JH,KA,KL,MP,MH,MN,ML,MZ,NL,OD,PB,RJ,SK,TN,TS,TR,UA,UK,UP,WB,AN,CH,DN,DD,DL,LD,PY]{2}\s*[0-9]{1,2}\s*[A-Z]{1,2}\s*[0-9]{1,4}\s*]?",cleanString)
for word in mystates:
if(word in result):
res = re.findall(word + "[0-9]{1,2}\s*[A-Z]{1,2}\s*[0-9]{1,4}\s*]?", result)
if(len(res) >0):
return(res[0])
return result