Update app.py
Browse files
app.py
CHANGED
|
@@ -153,10 +153,11 @@ def fig2img(fig):
|
|
| 153 |
|
| 154 |
|
| 155 |
# -------------------- OCR Stub --------------------
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
# -------------------- Visualization --------------------
|
|
@@ -178,10 +179,10 @@ def visualize_prediction(img, output_dict, threshold=0.5, id2label=None):
|
|
| 178 |
|
| 179 |
for score, (xmin, ymin, xmax, ymax), label in zip(scores, boxes, labels):
|
| 180 |
if "plate" in label.lower():
|
| 181 |
-
|
| 182 |
|
| 183 |
-
plate_text = read_plate(
|
| 184 |
-
vehicle_type = classify_plate_color(
|
| 185 |
toll, discount_msg = compute_discount(vehicle_type)
|
| 186 |
|
| 187 |
cursor.execute(
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
# -------------------- OCR Stub --------------------
|
| 156 |
+
def read_plate(plate_img):
|
| 157 |
+
results = reader.readtext(np.array(plate_img))
|
| 158 |
+
if results:
|
| 159 |
+
return results[0][1]
|
| 160 |
+
return "UNKNOWN"
|
| 161 |
|
| 162 |
|
| 163 |
# -------------------- Visualization --------------------
|
|
|
|
| 179 |
|
| 180 |
for score, (xmin, ymin, xmax, ymax), label in zip(scores, boxes, labels):
|
| 181 |
if "plate" in label.lower():
|
| 182 |
+
plate_img = img.crop((int(xmin), int(ymin), int(xmax), int(ymax)))
|
| 183 |
|
| 184 |
+
plate_text = read_plate(plate_img)
|
| 185 |
+
vehicle_type = classify_plate_color(plate_img)
|
| 186 |
toll, discount_msg = compute_discount(vehicle_type)
|
| 187 |
|
| 188 |
cursor.execute(
|