def convert_annotations(img_tag, names):
    """Find each ad in an img_tag and convert them to yolo-format annotations.

    Parameters
    ----------
    img_tag : xml.etree.ElementTree.Element
        CVAT-style tag for an image
    names : list
        An ordered list of labels, which describe boxes in images

    Returns
    -------
    (yolo_annotations, names) : tuple(str, list)
        yolo_annotations is a string containing all yolo-style annotations
            for the given img_tag, separated by '
' newline characters.
        names is a list containing all passed-in names, plus any new labels.

    """
    width = int(img_tag.get('width'))
    height = int(img_tag.get('height'))
    yolo_annotations = []
    for box in img_tag.findall('box'):
        label = box.get('label')
        xmin = float(box.get('xtl'))
        ymin = float(box.get('ytl'))
        xmax = float(box.get('xbr'))
        ymax = float(box.get('ybr'))
        if label not in names:
            names.append(label)
        label_id = names.index(label)
        yolo_x = (xmin + (xmax - xmin) / 2) / width
        yolo_y = (ymin + (ymax - ymin) / 2) / height
        yolo_w = (xmax - xmin) / width
        yolo_h = (ymax - ymin) / height
        yolo_annotations.append(
            f'{label_id} {yolo_x:.6f} {yolo_y:.6f} {yolo_w:.6f} {yolo_h:.6f}')
    return '\n'.join(yolo_annotations), names
