Sarvamangalak commited on
Commit
04a8d5b
·
verified ·
1 Parent(s): c11d90d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -14
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
- try:
67
- img = np.array(plate_img)
68
- hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
69
-
70
- green = np.sum(cv2.inRange(hsv, (35,40,40), (85,255,255)))
71
- yellow = np.sum(cv2.inRange(hsv, (15,50,50), (35,255,255)))
72
-
73
- if green > yellow:
74
- return "EV"
75
- elif yellow > green:
76
- return "Commercial"
77
- return "Personal"
78
- except:
79
- return "Unknown"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: