label = '{} {:.2f}'.format(predicted_class, score)
image = image.convert('RGB')
#***************************************
draw = ImageDraw.Draw(image)
#***************************************
label_size = draw.textsize(label, font)
top, left, bottom, right = box
top = max(0, np.floor(top + 0.5).astype('int32'))
left = max(0, np.floor(left + 0.5).astype('int32'))
bottom = min(image.size[1], np.floor(bottom + 0.5).astype('int32'))
right = min(image.size[0], np.floor(right + 0.5).astype('int32'))
print(label, (left, top), (right, bottom))
if top - label_size[1] >= 0:
text_origin = np.array([left, top - label_size[1]])
else:
text_origin = np.array([left, top + 1])
# My kingdom for a good redistributable image drawing library.
for i in range(thickness):
# **************************
# **************************
# 这个地方一定要注意
# 黑白图和彩色图不一样
# 黑白图用outline = (255)
# 彩图可以用 self.color[c]
draw.rectangle([left + i, top + i, right - i, bottom - i], outline=self.colors[c])