Ejemplo n.º 1
0
def matching_pairs_from_dirpath(
        kapture_dirpath: str) -> Iterable[Tuple[str, str]]:
    """
    Read and build Matches from kapture directory tree.
    """
    matches_dirpath = get_matches_fullpath(None, kapture_dirpath)
    # list all files there is
    # filter only match files (the ones endings with .matches)
    matches_filenames = populate_files_in_dirpath(
        matches_dirpath, FEATURE_FILE_EXTENSION[kapture.Matches])

    # remove the extensions and cut
    matching_pairs = (path_secure(matches_filename)
                      [:-len(FEATURE_FILE_EXTENSION[kapture.Matches])].split(
                          FEATURE_PAIR_PATH_SEPARATOR[kapture.Matches] + '/')
                      for matches_filename in matches_filenames)
    matching_pairs = ((matches[0], matches[1]) for matches in matching_pairs
                      if len(matches) == 2)
    return matching_pairs
Ejemplo n.º 2
0
def image_ids_from_feature_dirpath(
        kapture_type: Type[Union[kapture.Keypoints, kapture.Descriptors,
                                 kapture.GlobalFeatures, kapture.Matches]],
        kapture_dirpath: str = '') -> Dict[str, str]:
    """
    Populate feature files and returns their corresponding image_filename.

    :param kapture_type:
    :param kapture_dirpath:
    :return: image file path
    """
    feature_dirpath = get_features_fullpath(kapture_type, kapture_dirpath)
    # filter only files with proper extension and
    feature_filenames = populate_files_in_dirpath(
        feature_dirpath, FEATURE_FILE_EXTENSION[kapture_type])
    # remove file extensions to retrieve image name.
    image_filenames = (
        feature_filename[:-len(FEATURE_FILE_EXTENSION[kapture_type])]
        for feature_filename in feature_filenames)
    return image_filenames
Ejemplo n.º 3
0
 def test_populate(self):
     filepaths_retrieved = populate_files_in_dirpath(self._source_dirpath)
     self.assertEqual(set(self._filenames), set(filepaths_retrieved))