Spaces:
Sleeping
Sleeping
Shri Jayaram
commited on
Commit
·
2212fc3
1
Parent(s):
35003e1
font NA fix
Browse files
app.py
CHANGED
@@ -114,22 +114,23 @@ def calculate_pixel_per_metric(image, known_diameter_of_coin=25):
|
|
114 |
return width, height
|
115 |
|
116 |
# Inside your `plot_bbox` function, after drawing the bounding box:
|
|
|
117 |
for bbox, label in zip(data['bboxes'], data['labels']):
|
118 |
x1, y1, x2, y2 = bbox
|
119 |
draw.rectangle([x1, y1, x2, y2], outline="red", width=2)
|
120 |
-
draw.text((x1, y1), label, fill="red", font=
|
121 |
|
122 |
# Calculate dimensions
|
123 |
width, height = calculate_bbox_dimensions(bbox)
|
124 |
print(f"Label: {label}, Width: {width}, Height: {height}")
|
125 |
dimension_text = f"W: {width}, H: {height}"
|
126 |
-
draw.text((x1, y1 + 20), dimension_text, fill="red", font=
|
127 |
|
128 |
real_world_dimension_mm = 160
|
129 |
largest_dimension = max(width, height)
|
130 |
pixels_per_mm = largest_dimension / real_world_dimension_mm
|
131 |
ratio_text = f"Pixels/mm: {pixels_per_mm:.2f}"
|
132 |
-
draw.text((x1, y1 + 40), ratio_text, fill="red", font=
|
133 |
|
134 |
# buf = BytesIO()
|
135 |
# image_with_bboxes.save(buf, format='PNG')
|
|
|
114 |
return width, height
|
115 |
|
116 |
# Inside your `plot_bbox` function, after drawing the bounding box:
|
117 |
+
font = ImageFont.truetype("arial.ttf", 28)
|
118 |
for bbox, label in zip(data['bboxes'], data['labels']):
|
119 |
x1, y1, x2, y2 = bbox
|
120 |
draw.rectangle([x1, y1, x2, y2], outline="red", width=2)
|
121 |
+
draw.text((x1, y1), label, fill="red", font=font)
|
122 |
|
123 |
# Calculate dimensions
|
124 |
width, height = calculate_bbox_dimensions(bbox)
|
125 |
print(f"Label: {label}, Width: {width}, Height: {height}")
|
126 |
dimension_text = f"W: {width}, H: {height}"
|
127 |
+
draw.text((x1, y1 + 20), dimension_text, fill="red", font=font)
|
128 |
|
129 |
real_world_dimension_mm = 160
|
130 |
largest_dimension = max(width, height)
|
131 |
pixels_per_mm = largest_dimension / real_world_dimension_mm
|
132 |
ratio_text = f"Pixels/mm: {pixels_per_mm:.2f}"
|
133 |
+
draw.text((x1, y1 + 40), ratio_text, fill="red", font=font)
|
134 |
|
135 |
# buf = BytesIO()
|
136 |
# image_with_bboxes.save(buf, format='PNG')
|
arial.ttf
ADDED
Binary file (312 kB). View file
|
|