-
Notifications
You must be signed in to change notification settings - Fork 2
/
predicthelper.py
64 lines (58 loc) · 1.45 KB
/
predicthelper.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import preprocessing as seg
def rectify(s):
s = list(s)
for i in range(2):
if s[i]=='4':
s[i]='A'
if s[i]=='2':
s[i] = 'Z'
if s[i]=='1':
s[i] = 'I'
if s[i]=='8':
s[i] = 'B'
if s[i]=='6':
s[i] = 'G'
if s[i]=='0':
s[i] = 'O'
if s[i]=='5':
s[i] = 'S'
for i in range(2,4):
if s[i]=='A':
s[i]='4'
if s[i]=='Z':
s[i] = '2'
if s[i]=='I':
s[i] = '1'
if s[i]=='B':
s[i] = '8'
if s[i]=='G':
s[i] = '6'
if s[i]=='O':
s[i] = '0'
if s[i]=='S':
s[i] = '5'
for i in range(6,10):
if s[i]=='A':
s[i]='4'
if s[i]=='Z':
s[i] = '2'
if s[i]=='I':
s[i] = '1'
if s[i]=='B':
s[i] = '8'
if s[i]=='G':
s[i] = '6'
if s[i]=='O':
s[i] = '0'
if s[i]=='S':
s[i] = '5'
s = ''.join(s)
return s
def predict(im,reader,ALLOWED_LIST):
im=seg.getprocessed(im)
characters = reader.readtext(im, allowlist=ALLOWED_LIST)
characters.sort(key=lambda x:(x[0][0][0]+x[0][2][0])//2)
p=""
for i in range(len(characters)):
p+=characters[i][1]
return rectify(p)