Skip to content

Commit 90d467a

Browse files
authored
apply new style of display to function 'display'
1 parent 42c0bcd commit 90d467a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

utils/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,11 @@ def display(preds, imgs, obj_list, imshow=True, imwrite=False):
136136

137137
for j in range(len(preds[i]['rois'])):
138138
(x1, y1, x2, y2) = preds[i]['rois'][j].astype(np.int)
139-
cv2.rectangle(imgs[i], (x1, y1), (x2, y2), (255, 255, 0), 2)
140139
obj = obj_list[preds[i]['class_ids'][j]]
141140
score = float(preds[i]['scores'][j])
142141

143-
cv2.putText(imgs[i], '{}, {:.3f}'.format(obj, score),
144-
(x1, y1 + 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
145-
(255, 255, 0), 1)
142+
plot_one_box(imgs[i], [x1, y1, x2, y2], label=obj, score=score,
143+
color=color_list[get_index_label(obj, obj_list)])
146144
if imshow:
147145
cv2.imshow('img', imgs[i])
148146
cv2.waitKey(0)
@@ -245,6 +243,7 @@ def variance_scaling_(tensor, gain=1.):
245243

246244
return _no_grad_normal_(tensor, 0., std)
247245

246+
248247
STANDARD_COLORS = [
249248
'LawnGreen', 'Chartreuse', 'Aqua','Beige', 'Azure','BlanchedAlmond','Bisque',
250249
'Aquamarine', 'BlueViolet', 'BurlyWood', 'CadetBlue', 'AntiqueWhite',
@@ -271,21 +270,25 @@ def variance_scaling_(tensor, gain=1.):
271270
'WhiteSmoke', 'Yellow', 'YellowGreen'
272271
]
273272

273+
274274
def from_colorname_to_bgr(color):
275275
rgb_color=webcolors.name_to_rgb(color)
276276
result=(rgb_color.blue,rgb_color.green,rgb_color.red)
277277
return result
278278

279+
279280
def standard_to_bgr(list_color_name):
280281
standard= []
281282
for i in range(len(list_color_name)-36): #-36 used to match the len(obj_list)
282283
standard.append(from_colorname_to_bgr(list_color_name[i]))
283284
return standard
284285

286+
285287
def get_index_label(label, obj_list):
286288
index = int(obj_list.index(label))
287289
return index
288290

291+
289292
def plot_one_box(img, coord, label=None, score=None, color=None, line_thickness=None):
290293
tl = line_thickness or int(round(0.001 * max(img.shape[0:2]))) # line thickness
291294
color = color
@@ -298,3 +301,6 @@ def plot_one_box(img, coord, label=None, score=None, color=None, line_thickness=
298301
c2 = c1[0] + t_size[0]+s_size[0]+15, c1[1] - t_size[1] -3
299302
cv2.rectangle(img, c1, c2 , color, -1) # filled
300303
cv2.putText(img, '{}: {:.0%}'.format(label, score), (c1[0],c1[1] - 2), 0, float(tl) / 3, [0, 0, 0], thickness=tf, lineType=cv2.FONT_HERSHEY_SIMPLEX)
304+
305+
306+
color_list = standard_to_bgr(STANDARD_COLORS)

0 commit comments

Comments
 (0)