Skip to content

Commit 56ebd51

Browse files
committed
support for points and relative coordinates
1 parent a4a5508 commit 56ebd51

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

stackview/_add_bounding_boxes.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,19 @@ def add_bounding_boxes(image, bounding_boxes, line_width=2):
5252
for bbox in bounding_boxes:
5353
x = bbox['x']
5454
y = bbox['y']
55-
width = bbox['width']
56-
height = bbox['height']
55+
width = bbox['width'] if 'width' in bbox else 1
56+
height = bbox['height'] if 'height' in bbox else 1
5757
color_name = bbox['color'] if 'color' in bbox else "red"
5858

59+
if isinstance(x, float):
60+
x = int(x * img_with_boxes.shape[1])
61+
if isinstance(y, float):
62+
y = int(y * img_with_boxes.shape[0])
63+
if isinstance(width, float):
64+
width = int(width * img_with_boxes.shape[1])
65+
if isinstance(height, float):
66+
height = int(height * img_with_boxes.shape[0])
67+
5968
# Convert color name to RGB
6069
color = color_name_to_rgb(color_name)
6170

0 commit comments

Comments
 (0)