-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdata_formatter.py
275 lines (246 loc) · 11 KB
/
data_formatter.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
vehicle_codes = {
'make': [
{"id": "abarth", "name": "Abarth"},
{"id": "acura", "name": "Acura"},
{"id": "agrale", "name": "Agrale"},
{"id": "aixam", "name": "Aixam"},
{"id": "alfa-romeo", "name": "Alfa Romeo"},
{"id": "aro", "name": "Aro"},
{"id": "aston-martin", "name": "Aston Martin"},
{"id": "audi", "name": "Audi"},
{"id": "austin", "name": "Austin"},
{"id": "autobianchi", "name": "Autobianchi"},
{"id": "baic", "name": "Baic"},
{"id": "baw", "name": "Baw"},
{"id": "bedford", "name": "Bedford"},
{"id": "bentley", "name": "Bentley"},
{"id": "bmw", "name": "Bmw"},
{"id": "brilliance", "name": "Brilliance"},
{"id": "buick", "name": "Buick"},
{"id": "cadillac", "name": "Cadillac"},
{"id": "cam", "name": "Cam"},
{"id": "caravans-wohnm", "name": "Caravans Wohnm"},
{"id": "casalini", "name": "Casalini"},
{"id": "caterham", "name": "Caterham"},
{"id": "chana", "name": "Chana"},
{"id": "changhe", "name": "Changhe"},
{"id": "chery", "name": "Chery"},
{"id": "chevrolet", "name": "Chevrolet"},
{"id": "chrysler", "name": "Chrysler"},
{"id": "citroen", "name": "Citroen"},
{"id": "cmc", "name": "Cmc"},
{"id": "dacia", "name": "Dacia"},
{"id": "daewoo", "name": "Daewoo"},
{"id": "daihatsu", "name": "Daihatsu"},
{"id": "daimler", "name": "Daimler"},
{"id": "datsun", "name": "Datsun"},
{"id": "dodge", "name": "Dodge"},
{"id": "donkervoort", "name": "Donkervoort"},
{"id": "dr-motor", "name": "Dr Motor"},
{"id": "ds-automobiles", "name": "Ds Automobiles"},
{"id": "ducati", "name": "Ducati"},
{"id": "effa", "name": "Effa"},
{"id": "faw", "name": "Faw"},
{"id": "ferrari", "name": "Ferrari"},
{"id": "fiat", "name": "Fiat"},
{"id": "fisker", "name": "Fisker"},
{"id": "force", "name": "Force"},
{"id": "ford", "name": "Ford"},
{"id": "freightliner", "name": "Freightliner"},
{"id": "gac-gonow", "name": "Gac Gonow"},
{"id": "gaz", "name": "Gaz"},
{"id": "geely", "name": "Geely"},
{"id": "genesis", "name": "Genesis"},
{"id": "gmc", "name": "Gmc"},
{"id": "great-wall", "name": "Great Wall"},
{"id": "harley-davidson", "name": "Harley Davidson"},
{"id": "holden", "name": "Holden"},
{"id": "honda", "name": "Honda"},
{"id": "hummer", "name": "Hummer"},
{"id": "hyundai", "name": "Hyundai"},
{"id": "infiniti", "name": "Infiniti"},
{"id": "innocenti", "name": "Innocenti"},
{"id": "isuzu", "name": "Isuzu"},
{"id": "iveco", "name": "Iveco"},
{"id": "jac", "name": "Jac"},
{"id": "jaguar", "name": "Jaguar"},
{"id": "jeep", "name": "Jeep"},
{"id": "jmc", "name": "Jmc"},
{"id": "kawasaki", "name": "Kawasaki"},
{"id": "kenworth", "name": "Kenworth"},
{"id": "kia", "name": "Kia"},
{"id": "koda", "name": "Koda"},
{"id": "ktm", "name": "Ktm"},
{"id": "lada", "name": "Lada"},
{"id": "lamborghini", "name": "Lamborghini"},
{"id": "lancia", "name": "Lancia"},
{"id": "land-rover", "name": "Land Rover"},
{"id": "ldv", "name": "Ldv"},
{"id": "lexus", "name": "Lexus"},
{"id": "leyland", "name": "Leyland"},
{"id": "lifan", "name": "Lifan"},
{"id": "ligier", "name": "Ligier"},
{"id": "lincoln", "name": "Lincoln"},
{"id": "lotus", "name": "Lotus"},
{"id": "mahindra", "name": "Mahindra"},
{"id": "martin-motors", "name": "Martin Motors"},
{"id": "maruti-suzuki", "name": "Maruti Suzuki"},
{"id": "maserati", "name": "Maserati"},
{"id": "mazda", "name": "Mazda"},
{"id": "mclaren", "name": "Mclaren"},
{"id": "mercedes-benz", "name": "Mercedes Benz"},
{"id": "mercury", "name": "Mercury"},
{"id": "mg", "name": "Mg"},
{"id": "microcar", "name": "Microcar"},
{"id": "mini", "name": "Mini"},
{"id": "missing", "name": "Missing"},
{"id": "mitsubishi", "name": "Mitsubishi"},
{"id": "morgan", "name": "Morgan"},
{"id": "morris", "name": "Morris"},
{"id": "mp-lafer", "name": "Mp Lafer"},
{"id": "nissan", "name": "Nissan"},
{"id": "oldsmobile", "name": "Oldsmobile"},
{"id": "oldtimer", "name": "Oldtimer"},
{"id": "opel", "name": "Opel"},
{"id": "peterbilt", "name": "Peterbilt"},
{"id": "peugeot", "name": "Peugeot"},
{"id": "piaggio", "name": "Piaggio"},
{"id": "polaris", "name": "Polaris"},
{"id": "pontiac", "name": "Pontiac"},
{"id": "porsche", "name": "Porsche"},
{"id": "proton", "name": "Proton"},
{"id": "puma", "name": "Puma"},
{"id": "ram", "name": "Ram"},
{"id": "renault", "name": "Renault"},
{"id": "rolls-royce", "name": "Rolls Royce"},
{"id": "rover", "name": "Rover"},
{"id": "saab", "name": "Saab"},
{"id": "santana", "name": "Santana"},
{"id": "saturn", "name": "Saturn"},
{"id": "scania", "name": "Scania"},
{"id": "scion", "name": "Scion"},
{"id": "seat", "name": "Seat"},
{"id": "shelby", "name": "Shelby"},
{"id": "skoda", "name": "Skoda"},
{"id": "smart", "name": "Smart"},
{"id": "ssangyong", "name": "Ssangyong"},
{"id": "subaru", "name": "Subaru"},
{"id": "suzuki", "name": "Suzuki"},
{"id": "talbot", "name": "Talbot"},
{"id": "tata", "name": "Tata"},
{"id": "tesla", "name": "Tesla"},
{"id": "tofa", "name": "Tofa"},
{"id": "toyota", "name": "Toyota"},
{"id": "trabant", "name": "Trabant"},
{"id": "triumph", "name": "Triumph"},
{"id": "trucks-lkw", "name": "Trucks Lkw"},
{"id": "tvr", "name": "Tvr"},
{"id": "uaz", "name": "Uaz"},
{"id": "victory", "name": "Victory"},
{"id": "volkswagen", "name": "Volkswagen"},
{"id": "volvo", "name": "Volvo"},
{"id": "wartburg", "name": "Wartburg"},
{"id": "westfield", "name": "Westfield"},
{"id": "willys", "name": "Willys"},
{"id": "yamaha", "name": "Yamaha"},
{"id": "zastava", "name": "Zastava"},
],
'color': [
{"id": "black", "name": "Black"},
{"id": "blue", "name": "Blue"},
{"id": "brown", "name": "Brown"},
{"id": "gold-beige", "name": "Gold/Beige"},
{"id": "green", "name": "Green"},
{"id": "orange", "name": "Orange"},
{"id": "pink", "name": "Pink"},
{"id": "purple", "name": "Purple"},
{"id": "red", "name": "Red"},
{"id": "silver-gray", "name": "Silver/Gray"},
{"id": "white", "name": "White"},
{"id": "yellow", "name": "Yellow"}
],
'body': [
{"id": "antique", "name": "Antique", 'detail': 'body' },
{"id": "sedan-compact,sedan-convertible,sedan-sports,sedan-standard,sedan-wagon", "name": "Sedan", 'detail': 'all' },
{"id": "suv-crossover,suv-standard,suv-wagon", "name": "SUV", 'detail': 'all'},
{"id": "truck-standard", "name": "Truck", 'detail': 'all' },
{"id": "tractor-trailer", "name": "Tractor/Trailer", 'detail': 'body' },
{"id": "van-full", "name": "Commercial Van", 'detail': 'body' },
{"id": "van-mini", "name": "Minivan", 'detail': 'all' },
{"id": "motorcycle", "name": "Motorcycle", 'detail': 'body' },
{"id": "bus-commercial", "name": "Commercial Bus", 'detail': 'body' },
{"id": "bus-school", "name": "School Bus", 'detail': 'body' },
{"id": "emergency", "name": "Emergency Vehicle", 'detail': 'body' },
{"id": "taxi", "name": "Taxi", 'detail': 'body' },
{"id": "tractor-farm", "name": "Farm Tractor", 'detail': 'body' },
{"id": "trailer-rv", "name": "RV/Trailer", 'detail': 'body' },
{"id": "trailer-utility", "name": "Utility Trailer", 'detail': 'body' },
{"id": "truck-garbage", "name": "Garbage Truck", 'detail': 'body' },
]
}
bodyblend = {}
for bodycommad in vehicle_codes['body']:
for body in bodycommad['id'].split(","):
bodyblend[body] = {'name': bodycommad['name'], 'detail': bodycommad['detail']}
def parsevehicle(make, make_confidence, model, model_confidence, body, body_confidence, color, color_confidence):
THRESHOLD = 50.0
body_label = ''
if body_confidence > THRESHOLD:
if body in bodyblend and bodyblend[body]['detail'] == 'body':
return bodyblend[body]['name']
else:
body_label = bodyblend[body]['name']
has_make = False
makemodel_label = ''
if make_confidence > THRESHOLD or model_confidence > THRESHOLD:
has_make = True
if model_confidence > THRESHOLD:
makemodel_label = model.replace("_", " ").title()
elif make_confidence > THRESHOLD:
makemodel_label = make.replace("-", " ").title()
if color_confidence > THRESHOLD:
color_label = color.replace("-", " ").title().replace(" ", "/")
response = ''
if color_confidence > THRESHOLD:
response += color_label + " "
if has_make:
if model_confidence > THRESHOLD:
response += makemodel_label
else:
response += makemodel_label + " " + body_label
else:
response += body_label
if len(response) == 0:
return "Unknown"
return response
def get_vehicle_label(group):
response = ''
if group['data_type'] == 'alpr_group':
response = group['best_plate']
if group['best_region_confidence'] > 50.0:
response += f" ({group['best_region']})"
elif group['data_type'] == 'vehicle':
response = parsevehicle(group['vehicle']['make'][0]['name'], group['vehicle']['make'][0]['confidence'],
group['vehicle']['make_model'][0]['name'], group['vehicle']['make_model'][0]['confidence'],
group['vehicle']['body_type'][0]['name'], group['vehicle']['body_type'][0]['confidence'],
group['vehicle']['color'][0]['name'], group['vehicle']['color'][0]['confidence'],
)
return response
if __name__ == '__main__':
# TEST
print(parsevehicle('whocares1', 100,
'whocares2', 100,
'motorcycle', 55,
'whocares3', 100))
print(parsevehicle('rolls-royce', 100,
'whocares2', 0,
'sedan-compact', 55,
'black', 100))
print(parsevehicle('rolls-royce', 100,
'bmw_i-350', 100,
'sedan-compact', 55,
'black', 100))
print(parsevehicle('rolls-royce', 0,
'bmw_i-350', 0,
'sedan-compact', 55,
'black', 100))