Update app.py
Browse files
app.py
CHANGED
@@ -38,43 +38,68 @@ if submit:
|
|
38 |
frame = np.array(image)[...,::-1]
|
39 |
try:
|
40 |
plate_img = alpr(frame,license)
|
41 |
-
#plate_img = cv2.resize(plate_img,(200,50))
|
42 |
results = model(plate_img*255)
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
if
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
-
|
77 |
-
|
|
|
|
|
78 |
|
79 |
|
80 |
except Exception as e:
|
|
|
38 |
frame = np.array(image)[...,::-1]
|
39 |
try:
|
40 |
plate_img = alpr(frame,license)
|
|
|
41 |
results = model(plate_img*255)
|
42 |
+
control = max(results.pandas().xyxy[0].sort_values('ymin').iloc[:,1].values)
|
43 |
+
if control > 50:
|
44 |
+
name = results.pandas().xyxy[0].sort_values('ymin') #.iloc[:, -1] #ymin alwas bigger than 50 with bottom characters
|
45 |
+
ind = [ix for ix,i in enumerate(name.iloc[:,1]) if i>50][0]
|
46 |
+
upper_f_2 = name.iloc[:ind].sort_values("xmin").iloc[:,-1][:2]
|
47 |
+
upper_sort = name.iloc[:ind].sort_values("xmin").iloc[:,-1][2:] #add name column
|
48 |
+
bottom_sort = name.iloc[ind:].sort_values("xmin").iloc[:,-1]
|
49 |
+
upper_name = "".join([i for i in upper_sort])
|
50 |
+
upper_f_name = "".join([i for i in upper_f_2])
|
51 |
+
bottom_name = "".join([i for i in bottom_sort])
|
52 |
+
if "1" in upper_name:
|
53 |
+
upper_name.replace("1","I")
|
54 |
+
if "6" in upper_name:
|
55 |
+
upper_name.replace("6","G")
|
56 |
+
if "0" in upper_name:
|
57 |
+
upper_name.replace("0","O")
|
58 |
+
|
59 |
+
name = upper_f_name + upper_name + bottom_name
|
60 |
+
if name not in counter and name != '':
|
61 |
+
counter[name] = 1
|
62 |
+
if name in counter and name != '':
|
63 |
+
counter[name] += 1
|
64 |
+
plate_name = list((sorted(counter.items(), key=lambda item: item[1])))[-1][0]
|
65 |
+
st.write(plate_name)
|
66 |
+
|
67 |
+
else:
|
68 |
+
|
69 |
+
#Post-processing pre-requisite
|
70 |
+
decoder = results.pandas().xyxy[0].sort_values('xmin').iloc[:,0].values
|
71 |
+
compare = list(decoder[2:])
|
72 |
+
maks = None
|
73 |
+
for i in range(len(compare)):
|
74 |
+
if i == len(compare) - 1:
|
75 |
+
break
|
76 |
+
if maks == None:
|
77 |
+
maks = abs(compare[i] - compare[i + 1])
|
78 |
+
if abs(compare[i] - compare[i + 1]) > maks:
|
79 |
+
maks = abs(compare[i] - compare[i + 1])
|
80 |
+
w_index = (maks, i + 1)
|
81 |
+
|
82 |
+
name = results.pandas().xyxy[0].sort_values('xmin').iloc[:, -1]
|
83 |
+
name = "".join([i for i in name])
|
84 |
+
if name not in counter and name != '':
|
85 |
+
counter[name] = 1
|
86 |
+
if name in counter and name !='':
|
87 |
+
counter[name] +=1
|
88 |
+
plate_name = list((sorted(counter.items(),key = lambda item:item[1])))[-1][0]
|
89 |
+
#Post-processing happens after here
|
90 |
+
mid_chars = str(plate_name[2:int(w_index[1] + 2)]) # assign this as old mid chars
|
91 |
+
|
92 |
+
if "6" in mid_chars:
|
93 |
+
mid_chars = mid_chars.replace("6", "G") # assign this as new
|
94 |
+
if "1" in mid_chars:
|
95 |
+
mid_chars = mid_chars.replace("1", "I")
|
96 |
+
if "0" in mid_chars:
|
97 |
+
mid_chars = mid_chars.replace("0", "O")
|
98 |
|
99 |
+
new_plate_name = plate_name.replace(plate_name[2:int(w_index[1] + 2)], mid_chars)
|
100 |
+
|
101 |
+
#cv2.imshow("Plate", plate_img)
|
102 |
+
st.write(new_plate_name)
|
103 |
|
104 |
|
105 |
except Exception as e:
|