shrey14 commited on
Commit
c9068cc
·
verified ·
1 Parent(s): f3e768f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -26,7 +26,7 @@ BLACK = (0, 0, 0)
26
 
27
  # Load font for labeling
28
  try:
29
- font = ImageFont.truetype("arial.ttf", 10)
30
  except:
31
  font = ImageFont.load_default()
32
 
@@ -76,8 +76,19 @@ def process_image(image_path):
76
  total_counts[class_name] += 1
77
  x_min, y_min = x1 + obj["x"] - obj["width"] // 2, y1 + obj["y"] - obj["height"] // 2
78
  x_max, y_max = x1 + obj["x"] + obj["width"] // 2, y1 + obj["y"] + obj["height"] // 2
 
 
79
  draw_final.rectangle([x_min, y_min, x_max, y_max], outline=GREEN, width=2)
80
- draw_final.text((x_min, y_min - 10), class_name, fill=WHITE, font=font)
 
 
 
 
 
 
 
 
 
81
 
82
  # Save the final processed image
83
  final_image_path = "processed_image.png"
 
26
 
27
  # Load font for labeling
28
  try:
29
+ font = ImageFont.truetype("arial.ttf", 14)
30
  except:
31
  font = ImageFont.load_default()
32
 
 
76
  total_counts[class_name] += 1
77
  x_min, y_min = x1 + obj["x"] - obj["width"] // 2, y1 + obj["y"] - obj["height"] // 2
78
  x_max, y_max = x1 + obj["x"] + obj["width"] // 2, y1 + obj["y"] + obj["height"] // 2
79
+
80
+ # Draw bounding box
81
  draw_final.rectangle([x_min, y_min, x_max, y_max], outline=GREEN, width=2)
82
+
83
+ # Draw extended label above the bounding box
84
+ text_size = draw_final.textbbox((0, 0), class_name, font=font)
85
+ text_width = text_size[2] - text_size[0]
86
+ text_height = text_size[3] - text_size[1]
87
+ text_x = x_min
88
+ text_y = y_min - text_height - 5 if y_min - text_height - 5 > 0 else y_max + 5
89
+
90
+ draw_final.rectangle([text_x, text_y, text_x + text_width + 6, text_y + text_height + 2], fill=BLACK)
91
+ draw_final.text((text_x + 3, text_y), class_name, fill=WHITE, font=font)
92
 
93
  # Save the final processed image
94
  final_image_path = "processed_image.png"