Update app.py
Browse files
app.py
CHANGED
|
@@ -63,20 +63,46 @@ def compute_discount(vehicle_type):
|
|
| 63 |
return BASE_AMT
|
| 64 |
|
| 65 |
def classify_plate_color(plate_img):
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
def read_plate(plate_img):
|
| 82 |
try:
|
|
|
|
| 63 |
return BASE_AMT
|
| 64 |
|
| 65 |
def classify_plate_color(plate_img):
|
| 66 |
+
hsv = cv2.cvtColor(plate_img, cv2.COLOR_BGR2HSV)
|
| 67 |
+
|
| 68 |
+
# Masks for colors
|
| 69 |
+
masks = {}
|
| 70 |
+
|
| 71 |
+
# White
|
| 72 |
+
masks["white"] = cv2.inRange(hsv, np.array([0, 0, 180]), np.array([180, 60, 255]))
|
| 73 |
+
|
| 74 |
+
# Yellow
|
| 75 |
+
masks["yellow"] = cv2.inRange(hsv, np.array([15, 80, 80]), np.array([40, 255, 255]))
|
| 76 |
+
|
| 77 |
+
# Green
|
| 78 |
+
masks["green"] = cv2.inRange(hsv, np.array([35, 50, 50]), np.array([85, 255, 255]))
|
| 79 |
+
|
| 80 |
+
# Red
|
| 81 |
+
masks["red1"] = cv2.inRange(hsv, np.array([0, 70, 50]), np.array([10, 255, 255]))
|
| 82 |
+
masks["red2"] = cv2.inRange(hsv, np.array([170, 70, 50]), np.array([180, 255, 255]))
|
| 83 |
+
masks["red"] = masks["red1"] + masks["red2"]
|
| 84 |
+
|
| 85 |
+
# Blue
|
| 86 |
+
masks["blue"] = cv2.inRange(hsv, np.array([90, 50, 50]), np.array([130, 255, 255]))
|
| 87 |
+
|
| 88 |
+
# Count pixels
|
| 89 |
+
color_counts = {color: np.sum(mask) for color, mask in masks.items()}
|
| 90 |
+
|
| 91 |
+
dominant_color = max(color_counts, key=color_counts.get)
|
| 92 |
+
|
| 93 |
+
# Classification logic
|
| 94 |
+
if dominant_color == "white":
|
| 95 |
+
return "Private Vehicle"
|
| 96 |
+
elif dominant_color == "yellow":
|
| 97 |
+
return "Commercial Vehicle"
|
| 98 |
+
elif dominant_color == "green":
|
| 99 |
+
return "Electric Vehicle (EV)"
|
| 100 |
+
elif dominant_color == "red":
|
| 101 |
+
return "Temporary Registration Vehicle"
|
| 102 |
+
elif dominant_color == "blue":
|
| 103 |
+
return "Diplomatic Vehicle"
|
| 104 |
+
else:
|
| 105 |
+
return "Unknown Vehicle Type"
|
| 106 |
|
| 107 |
def read_plate(plate_img):
|
| 108 |
try:
|