Пример #1
0
def test_drop_orientation():
    img_file = 'tests/data/test_img2.jpg'
    output_file = drop_orientation(img_file)
    assert output_file is img_file

    img_file = 'tests/data/test_img1.jpg'
    tmp_dir = tempfile.TemporaryDirectory()
    dst_file = shutil.copy(img_file, tmp_dir.name)
    output_file = drop_orientation(dst_file)
    assert output_file[-3:] == 'png'
Пример #2
0
def collect_files(img_dir, gt_dir):
    """Collect all images and their corresponding groundtruth files.

    Args:
        img_dir(str): The image directory
        gt_dir(str): The groundtruth directory

    Returns:
        files(list): The list of tuples (img_file, groundtruth_file)
    """
    assert isinstance(img_dir, str)
    assert img_dir
    assert isinstance(gt_dir, str)
    assert gt_dir

    # note that we handle png and jpg only. Pls convert others such as gif to
    # jpg or png offline
    suffixes = ['.png', '.PNG', '.jpg', '.JPG', '.jpeg', '.JPEG']
    imgs_list = []
    for suffix in suffixes:
        imgs_list.extend(glob.glob(osp.join(img_dir, '*' + suffix)))

    imgs_list = [
        drop_orientation(f) if is_not_png(f) else f for f in imgs_list
    ]

    files = []
    for img_file in imgs_list:
        gt_file = gt_dir + '/gt_' + osp.splitext(
            osp.basename(img_file))[0] + '.txt'
        files.append((img_file, gt_file))
    assert len(files), f'No images found in {img_dir}'
    print(f'Loaded {len(files)} images from {img_dir}')

    return files