Spaces:
Running
on
Zero
Running
on
Zero
better box visuals
Browse files
app.py
CHANGED
|
@@ -46,13 +46,19 @@ def draw_bounding_boxes(image, refs, extract_images=False):
|
|
| 46 |
draw = ImageDraw.Draw(img_draw)
|
| 47 |
overlay = Image.new('RGBA', img_draw.size, (0, 0, 0, 0))
|
| 48 |
draw2 = ImageDraw.Draw(overlay)
|
| 49 |
-
font = ImageFont.
|
| 50 |
crops = []
|
| 51 |
|
|
|
|
|
|
|
|
|
|
| 52 |
for ref in refs:
|
| 53 |
label = ref[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
coords = eval(ref[2])
|
| 55 |
-
color = (np.random.randint(50, 255), np.random.randint(50, 255), np.random.randint(50, 255))
|
| 56 |
color_a = color + (60,)
|
| 57 |
|
| 58 |
for box in coords:
|
|
|
|
| 46 |
draw = ImageDraw.Draw(img_draw)
|
| 47 |
overlay = Image.new('RGBA', img_draw.size, (0, 0, 0, 0))
|
| 48 |
draw2 = ImageDraw.Draw(overlay)
|
| 49 |
+
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 25)
|
| 50 |
crops = []
|
| 51 |
|
| 52 |
+
color_map = {}
|
| 53 |
+
np.random.seed(42)
|
| 54 |
+
|
| 55 |
for ref in refs:
|
| 56 |
label = ref[1]
|
| 57 |
+
if label not in color_map:
|
| 58 |
+
color_map[label] = (np.random.randint(50, 255), np.random.randint(50, 255), np.random.randint(50, 255))
|
| 59 |
+
|
| 60 |
+
color = color_map[label]
|
| 61 |
coords = eval(ref[2])
|
|
|
|
| 62 |
color_a = color + (60,)
|
| 63 |
|
| 64 |
for box in coords:
|