Update app.py
Browse files
app.py
CHANGED
@@ -41,6 +41,19 @@ if submit:
|
|
41 |
#plate_img = cv2.resize(plate_img,(200,50))
|
42 |
results = model(plate_img*255)
|
43 |
#print(results.xyxy[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
name = results.pandas().xyxy[0].sort_values('xmin').iloc[:, -1]
|
45 |
name = "".join([i for i in name])
|
46 |
if name not in counter and name != '':
|
@@ -48,10 +61,20 @@ if submit:
|
|
48 |
if name in counter and name !='':
|
49 |
counter[name] +=1
|
50 |
plate_name = list((sorted(counter.items(),key = lambda item:item[1])))[-1][0]
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
#cv2.imshow("Plate", plate_img)
|
54 |
-
st.write(
|
55 |
|
56 |
|
57 |
except Exception as e:
|
|
|
41 |
#plate_img = cv2.resize(plate_img,(200,50))
|
42 |
results = model(plate_img*255)
|
43 |
#print(results.xyxy[0])
|
44 |
+
#Post-processing pre-requisite
|
45 |
+
decoder = results.pandas().xyxy[0].sort_values('xmin').iloc[:,0].values
|
46 |
+
compare = list(decoder[2:])
|
47 |
+
maks = None
|
48 |
+
for i in range(len(compare)):
|
49 |
+
if i == len(compare) - 1:
|
50 |
+
break
|
51 |
+
if maks == None:
|
52 |
+
maks = abs(compare[i] - compare[i + 1])
|
53 |
+
if abs(compare[i] - compare[i + 1]) > maks:
|
54 |
+
maks = abs(compare[i] - compare[i + 1])
|
55 |
+
w_index = (maks, i + 1)
|
56 |
+
|
57 |
name = results.pandas().xyxy[0].sort_values('xmin').iloc[:, -1]
|
58 |
name = "".join([i for i in name])
|
59 |
if name not in counter and name != '':
|
|
|
61 |
if name in counter and name !='':
|
62 |
counter[name] +=1
|
63 |
plate_name = list((sorted(counter.items(),key = lambda item:item[1])))[-1][0]
|
64 |
+
#Post-processing happens after here
|
65 |
+
mid_chars = str(plate_name[2:int(w_index[1] + 2)]) # assign this as old mid chars
|
66 |
+
|
67 |
+
if "6" in mid_chars:
|
68 |
+
mid_chars = mid_chars.replace("6", "G") # assign this as new
|
69 |
+
if "1" in mid_chars:
|
70 |
+
mid_chars = mid_chars.replace("1", "I")
|
71 |
+
if "0" in mid_chars:
|
72 |
+
mid_chars = mid_chars.replace("0", "O")
|
73 |
+
|
74 |
+
new_plate_name = plate_name.replace(plate_name[2:int(w_index[1] + 2)], mid_chars)
|
75 |
|
76 |
#cv2.imshow("Plate", plate_img)
|
77 |
+
st.write(new_plate_name)
|
78 |
|
79 |
|
80 |
except Exception as e:
|