def visualize_prediction(self, det_id, image, box, label, score, mask, mesh, alpha=0.6, dpi=200):
    mask_color = np.array(self.colors[label], dtype=np.float32)
    cat_name = self.cat_names[label]
    thickness = max([int(np.ceil((0.001 * image.shape[0]))), 1])
    box_color = (0, 255, 0)
    text_color = (218, 227, 218)
    composite = image.copy().astype(np.float32)
    idx = mask.nonzero()
    composite[idx[:, 0], idx[:, 1], :] *= (1.0 - alpha)
    composite[idx[:, 0], idx[:, 1], :] += (alpha * mask_color)
    (x0, y0, x1, y1) = (int((x + 0.5)) for x in box)
    composite = cv2.rectangle(composite, (x0, y0), (x1, y1), color=box_color, thickness=thickness)
    composite = composite.astype(np.uint8)
    font_scale = (0.001 * image.shape[0])
    font_thickness = thickness
    font = cv2.FONT_HERSHEY_TRIPLEX
    text = ('%s %.3f' % (cat_name, score))
    ((text_w, text_h), _) = cv2.getTextSize(text, font, font_scale, font_thickness)
    if ((x0 + text_w) > composite.shape[1]):
        x0 = (composite.shape[1] - text_w)
    if ((y0 - int((1.2 * text_h))) < 0):
        y0 = int((1.2 * text_h))
    back_topleft = (x0, (y0 - int((1.3 * text_h))))
    back_bottomright = ((x0 + text_w), y0)
    cv2.rectangle(composite, back_topleft, back_bottomright, box_color, (- 1))
    text_bottomleft = (x0, (y0 - int((0.2 * text_h))))
    cv2.putText(composite, text, text_bottomleft, font, font_scale, text_color, thickness=font_thickness, lineType=cv2.LINE_AA)
    save_file = os.path.join(self.output_dir, ('%d_mask_%s_%.3f.png' % (det_id, cat_name, score)))
    cv2.imwrite(save_file, composite[:, :, ::(- 1)])
    save_file = os.path.join(self.output_dir, ('%d_mesh_%s_%.3f.obj' % (det_id, cat_name, score)))
    (verts, faces) = mesh.get_mesh_verts_faces(0)
    save_obj(save_file, verts, faces)
def visualize_prediction(self, det_id, image, box, label, score, mask, mesh, alpha=0.6, dpi=200):
    mask_color = np.array(self.colors[label], dtype=np.float32)
    cat_name = self.cat_names[label]
    thickness = max([int(np.ceil((0.001 * image.shape[0]))), 1])
    box_color = (0, 255, 0)
    text_color = (218, 227, 218)
    composite = image.copy().astype(np.float32)
    idx = mask.nonzero()
    composite[idx[:, 0], idx[:, 1], :] *= (1.0 - alpha)
    composite[idx[:, 0], idx[:, 1], :] += (alpha * mask_color)
    (x0, y0, x1, y1) = (int((x + 0.5)) for x in box)
    composite = cv2.rectangle(composite, (x0, y0), (x1, y1), color=box_color, thickness=thickness)
    composite = composite.astype(np.uint8)
    font_scale = (0.001 * image.shape[0])
    font_thickness = thickness
    font = cv2.FONT_HERSHEY_TRIPLEX
    text = ('%s %.3f' % (cat_name, score))
    ((text_w, text_h), _) = cv2.getTextSize(text, font, font_scale, font_thickness)
    if ((x0 + text_w) > composite.shape[1]):
        x0 = (composite.shape[1] - text_w)
    if ((y0 - int((1.2 * text_h))) < 0):
        y0 = int((1.2 * text_h))
    back_topleft = (x0, (y0 - int((1.3 * text_h))))
    back_bottomright = ((x0 + text_w), y0)
    cv2.rectangle(composite, back_topleft, back_bottomright, box_color, (- 1))
    text_bottomleft = (x0, (y0 - int((0.2 * text_h))))
    cv2.putText(composite, text, text_bottomleft, font, font_scale, text_color, thickness=font_thickness, lineType=cv2.LINE_AA)
    save_file = os.path.join(self.output_dir, ('%d_mask_%s_%.3f.png' % (det_id, cat_name, score)))
    cv2.imwrite(save_file, composite[:, :, ::(- 1)])
    save_file = os.path.join(self.output_dir, ('%d_mesh_%s_%.3f.obj' % (det_id, cat_name, score)))
    (verts, faces) = mesh.get_mesh_verts_faces(0)
    save_obj(save_file, verts, faces)