yolox/utils/visualize.py文件中,具体对应修改位置注释有详细说明。
color = (_COLORS[cls_id] * 255).astype(np.uint8).tolist()
text = '{}:{:.2f}%'.format(class_names[cls_id], score * 100)# YOLOX的百分比显示方式 保留一位小数且冒号改为空格显示方式
txt_color = (0, 0, 0) if np.mean(_COLORS[cls_id]) > 0.5 else (255, 255, 255)
font = cv2.FONT_HERSHEY_SIMPLEX
txt_size = cv2.getTextSize(text, font, 3, 1)[0] #第一个数字1代表文字背景块大小 #最后一个数字1代表框的粗细
cv2.rectangle(img, (x0, y0), (x1, y1), color, 5)
txt_bk_color = (_COLORS[cls_id] * 255 * 0.7).astype(np.uint8).tolist()
cv2.rectangle(
img,
(x0, y0 + 1),
(x0 + txt_size[0] + 1, y0 + int(1.5*txt_size[1])),
txt_bk_color,
-1
)
cv2.putText(img, text, (x0, y0 + txt_size[1]), font, 3, txt_color, thickness=3)#第一个数字1代表标签字体的大小、thickness后的数字5代表标签字体的粗细