def draw_boxes_on_image()

in sagemaker/src/utils.py [0:0]


def draw_boxes_on_image(pred, label, images):
    ''' Function to draw multiple bounding boxes on the images. Predicted bounding boxes will be
    presented with a dotted line and actual boxes are presented with a solid line.
    Parameters
    ----------
    
    pred: [n x [x, y, w, h]]
        The predicted bounding boxes in percentages. 
        n is the number of bounding boxes predicted on an image
    label: [n x [x, y, w, h]]
        The actual bounding boxes in percentages
        n is the number of bounding boxes predicted on an image
    images: [[np.array]]
        The correponding images.
    Returns
    -------
    images: [[np.array]]
        Images with bounding boxes printed on them.
    '''
    image_h, image_w = images.shape[-2:]
    label[:, :, 0], label[:, :, 1] = label[:, :, 0] * image_w, label[:, :, 1] * image_h
    label[:, :, 2], label[:, :, 3] = label[:, :, 2] * image_w, label[:, :, 3] * image_h
    for i in range(len(pred)):
        pred_b = pred[i]
        pred_b[:, 0], pred_b[:, 1] = pred_b[:, 0] * image_w, pred_b[:, 1] * image_h
        pred_b[:, 2], pred_b[:, 3] = pred_b[:, 2] * image_w, pred_b[:, 3] * image_h

        image = images[i, 0]
        for j in range(pred_b.shape[0]):
            image = draw_box(pred_b[j, :], image, line_type="dotted")

        for k in range(label.shape[1]):
            image = draw_box(label[i, k, :], image, line_type="solid")
        images[i, 0, :, :] = image
    return images