Sarvamangalak commited on
Commit
8d3cf36
·
verified ·
1 Parent(s): 4ac86bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -65,9 +65,9 @@ def compute_discount(vehicle_type):
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
- # Color masks
71
  green_mask = cv2.inRange(hsv, (35, 40, 40), (85, 255, 255))
72
  yellow_mask = cv2.inRange(hsv, (15, 50, 50), (35, 255, 255))
73
  white_mask = cv2.inRange(hsv, (0, 0, 200), (180, 40, 255))
@@ -85,6 +85,9 @@ def classify_plate_color(plate_img):
85
  else:
86
  return "Unknown"
87
 
 
 
 
88
  def read_plate(plate_img):
89
  try:
90
  gray = cv2.cvtColor(np.array(plate_img), cv2.COLOR_RGB2GRAY)
@@ -166,15 +169,24 @@ def visualize(img, output, id2label, threshold):
166
 
167
  def get_dashboard():
168
  df = pd.read_sql("SELECT * FROM vehicles", conn)
169
- fig, ax = plt.subplots()
170
 
171
  if df.empty:
172
- ax.text(0.5,0.5,"No data yet",ha="center")
 
173
  ax.axis("off")
174
  return fig
175
 
176
- df["type"].value_counts().plot(kind="bar", ax=ax)
177
- ax.set_title("Vehicle Types")
 
 
 
 
 
 
 
 
178
  return fig
179
 
180
  # ---------------- FEEDBACK ----------------
 
65
  def classify_plate_color(plate_img):
66
  try:
67
  img = np.array(plate_img)
68
+ img = cv2.GaussianBlur(img, (5,5), 0)
69
  hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
70
 
 
71
  green_mask = cv2.inRange(hsv, (35, 40, 40), (85, 255, 255))
72
  yellow_mask = cv2.inRange(hsv, (15, 50, 50), (35, 255, 255))
73
  white_mask = cv2.inRange(hsv, (0, 0, 200), (180, 40, 255))
 
85
  else:
86
  return "Unknown"
87
 
88
+ except Exception as e:
89
+ return "Unknown"
90
+
91
  def read_plate(plate_img):
92
  try:
93
  gray = cv2.cvtColor(np.array(plate_img), cv2.COLOR_RGB2GRAY)
 
169
 
170
  def get_dashboard():
171
  df = pd.read_sql("SELECT * FROM vehicles", conn)
172
+ fig, ax = plt.subplots(figsize=(8,5))
173
 
174
  if df.empty:
175
+ ax.text(0.5, 0.5, "No vehicle data yet",
176
+ ha="center", va="center", fontsize=12)
177
  ax.axis("off")
178
  return fig
179
 
180
+ counts = df["type"].value_counts()
181
+
182
+ counts.plot(kind="bar", ax=ax)
183
+
184
+ ax.set_title("Vehicle Classification Distribution", fontsize=12)
185
+ ax.set_xlabel("Vehicle Type")
186
+ ax.set_ylabel("Number of Vehicles")
187
+ ax.tick_params(axis='x', rotation=30)
188
+
189
+ plt.tight_layout()
190
  return fig
191
 
192
  # ---------------- FEEDBACK ----------------