RivianG commited on
Commit
9b5d89a
1 Parent(s): e70b801

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -35
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
- #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 != '':
60
- counter[name] = 1
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:
 
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: