def draw_bboxes()

in model/utils/visualize_bboxes.py [0:0]


def draw_bboxes(bboxes, load_path, save_path, verbose=False):
    """Draw bounding boxes given the screenpath and list of bboxes.

    Args:
        bboxes: List of all bounding boxes
        load_path: Path to load the screenshot
        save_path: Path to save the screenshot with bounding boxes
        verbose: Print out status statements
    """
    # Read images and draw rectangles.
    image = Image.open(load_path)
    draw = ImageDraw.Draw(image)
    # Get a font.
    font = ImageFont.load_default()
    # font = ImageFont.truetype("arial.ttf", size=20)
    offset = 2
    for index, bbox_datum in enumerate(bboxes):
        object_index = bbox_datum.get("index", index)
        verts = bbox_datum["bbox"]
        draw.rectangle(
            [(verts[0], verts[1]), (verts[0] + verts[3], verts[1] + verts[2])]
        )
        # Draw text with black background.
        text = str(object_index)
        text_width, text_height = font.getsize(text)
        draw.rectangle(
            (
                verts[0] + offset,
                verts[1] + offset,
                verts[0] + 2 * offset + text_width,
                verts[1] + 2 * offset + text_height,
            ),
            fill="black",
        )
        draw.text(
            (verts[0] + offset, verts[1] + offset),
            str(object_index),  # str(index)
            fill=(255, 255, 255),
            font=font,
        )
    # Save the image with bbox drawn.
    if verbose:
        print("Saving: {}".format(save_path))
    image.save(save_path, "PNG")