@@ -164,9 +164,12 @@ def draw_bounding_boxes(
164
164
else : # BBoxes.__instancecheck__(Dict[str, Sequence[BBox]])
165
165
draw_labels = True
166
166
167
+ # colors: Union[Sequence[Color], Dict[str, Color]]
167
168
if colors is None :
168
169
# TODO: default to one of @pmeir's suggestions as a seq
169
- pass
170
+ colors_ : Sequence [Color ] = colors
171
+ else :
172
+ colors_ : Dict [str , Color ] = colors
170
173
171
174
from PIL import Image , ImageDraw
172
175
# Add 0.5 after unnormalizing to [0, 255] to round to nearest integer
@@ -176,20 +179,20 @@ def draw_bounding_boxes(
176
179
draw = ImageDraw .Draw (im )
177
180
178
181
if bboxes_is_dict :
179
- if Sequence [Color ].__instancecheck__ (colors ):
182
+ if Sequence [Color ].__instancecheck__ (colors_ ):
180
183
# align the colors seq with the bbox classes
181
- colors = dict (zip (sorted (bboxes .keys ()), colors ))
184
+ colors = dict (zip (sorted (bboxes .keys ()), colors_ ))
182
185
183
- for i , ( bbox_class , bbox ) in enumerate (bboxes .items ()):
184
- draw .rectangle (bbox , outline = colors [bbox_class ], width = width )
186
+ for bbox_class , bbox in enumerate (bboxes .items ()):
187
+ draw .rectangle (bbox , outline = colors_ [bbox_class ], width = width )
185
188
if draw_labels :
186
189
# TODO: this will probably overlap with the bbox
187
190
# hard-code in a margin for the label?
188
191
label_tl_x , label_tl_y , _ , _ = bbox
189
192
draw .text ((label_tl_x , label_tl_y ), bbox_class )
190
193
else : # bboxes_is_seq
191
194
for i , bbox in enumerate (bboxes ):
192
- draw .rectangle (bbox , outline = colors [i ], width = width )
195
+ draw .rectangle (bbox , outline = colors_ [i ], width = width )
193
196
194
197
from numpy import array as to_numpy_array
195
198
return torch .from_numpy (to_numpy_array (im ))
0 commit comments