Update app.py
Browse files
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",
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"
|