def format_image_bboxes(bboxes_on_image, class_dict, crop_size=512):
    """Convert ImageAug BoundingBoxOnImage object to YOLO fmt labels

    Parameters
    ----------
    bboxes_on_image: imgaug.imgaug.BoundingBoxexOnImage
        ImgAug object containing all bboxes
    class_dict: dict
        Dictionary containing class labels as keys and class numbers as objects

    Returns
    -------
    formatted_bboxes: list
        List of strings formatted in YOLO format for writing to text file.
    """

    formatted_bboxes = []

    # Ensure that some bounding boxes exist
    if bboxes_on_image:
        for bbox in bboxes_on_image.bounding_boxes:
            coords = [(bbox.x1 + bbox.width / 2.) / crop_size,
                      (bbox.y1 + bbox.height /2.) / crop_size,
                      bbox.width / crop_size,
                      bbox.height / crop_size]
            for coord_i, coord in enumerate(coords):
                if coord <= 0:
                    coords[coord_i] = 1e-8
                if coord >= 1:
                    coords[coord_i] = 1 - 1e-8

            line = '{cls} {x:.8f} {y:.8f} {w:.8f} {h:.8f}\n'.format(
                cls=bbox.label, x=coords[0], y=coords[1], w=coords[2],
                h=coords[3])
            formatted_bboxes.append(line)

    return formatted_bboxes