def save_matches(data: DataSetBase, images_ref, matched_pairs): """Given pairwise matches (image 1, image 2) - > matches, save them such as only {image E images_ref} will store the matches. """ matches_per_im1 = {im: {} for im in images_ref} for (im1, im2), m in matched_pairs.items(): matches_per_im1[im1][im2] = m for im1, im1_matches in matches_per_im1.items(): data.save_matches(im1, im1_matches)
def save_matches(data: DataSetBase, images_ref, matched_pairs): """Given pairwise matches (image 1, image 2) - > matches, save them such as only {image E images_ref} will store the matches. """ images_ref_set = set(images_ref) matches_per_im1 = {im: {} for im in images_ref} for (im1, im2), m in matched_pairs.items(): if im1 in images_ref_set: matches_per_im1[im1][im2] = m elif im2 in images_ref_set: matches_per_im1[im2][im1] = m else: raise RuntimeError( "Couldn't save matches for {}. No image found in images_ref.". format((im1, im2))) for im1, im1_matches in matches_per_im1.items(): data.save_matches(im1, im1_matches)