def draw_labels(img, labels, label_colors, convert=True):
"""
Draw the labels on top of the input image
:param img: the image being classified
:param labels: the output of the neural network
:param label_colors: the label color map defined in the source
:param convert: should the output be converted to RGB
"""
labels_colored = np.zeros_like(img)
for label in label_colors:
label_mask = labels == label
labels_colored[label_mask] = label_colors[label]
img = cv2.addWeighted(img, 1, labels_colored, 0.8, 0)
if not convert:
return img
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
#-------------------------------------------------------------------------------
评论列表
文章目录