From 1e7d6795060a6518b7336738eff250403dcbae50 Mon Sep 17 00:00:00 2001 From: Dillon DuPont Date: Thu, 27 Mar 2025 11:16:13 -0400 Subject: [PATCH] included detection bboxes in label collision check --- libs/som/som/visualization.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/som/som/visualization.py b/libs/som/som/visualization.py index 4212379c..5c270c28 100644 --- a/libs/som/som/visualization.py +++ b/libs/som/som/visualization.py @@ -112,10 +112,18 @@ class BoxAnnotator: # Keep track of used label areas to check for collisions used_areas = [] - # Store label information for second pass + # Store label information for third pass labels_to_draw = [] - # First pass: Draw all bounding boxes + # First pass: Initialize used_areas with all bounding boxes + for detection in detections: + box = detection["bbox"] + x1, y1, x2, y2 = [ + int(coord * dim) for coord, dim in zip(box, [image.width, image.height] * 2) + ] + used_areas.append((x1, y1, x2, y2)) + + # Second pass: Draw all bounding boxes for idx, detection in enumerate(detections, 1): # Get box coordinates box = detection["bbox"] @@ -233,7 +241,7 @@ class BoxAnnotator: } ) - # Second pass: Draw all labels on top + # Third pass: Draw all labels on top for label_info in labels_to_draw: # Draw background box with white outline draw.rectangle(