Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions hloc/extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def __init__(self, root, conf, paths=None):
self.conf = conf = SimpleNamespace(**{**self.default_conf, **conf})
self.root = root


if paths is None:
paths = []
for g in conf.globs:
Expand All @@ -184,6 +185,7 @@ def __init__(self, root, conf, paths=None):
def __getitem__(self, idx):
name = self.names[idx]
image = read_image(self.root / name, self.conf.grayscale)

image = image.astype(np.float32)
size = image.shape[:2][::-1]

Expand Down Expand Up @@ -217,10 +219,12 @@ def main(conf: Dict,
as_half: bool = True,
image_list: Optional[Union[Path, List[str]]] = None,
feature_path: Optional[Path] = None,
overwrite: bool = False) -> Path:
overwrite: bool = False,
mask_dir: Optional[Path] = None,
) -> Path:
logger.info('Extracting local features with configuration:'
f'\n{pprint.pformat(conf)}')

loader = ImageDataset(image_dir, conf['preprocessing'], image_list)
loader = torch.utils.data.DataLoader(loader, num_workers=1)

Expand Down Expand Up @@ -250,9 +254,18 @@ def main(conf: Dict,
size = np.array(data['image'].shape[-2:][::-1])
scales = (original_size / size).astype(np.float32)
pred['keypoints'] = (pred['keypoints'] + .5) * scales[None] - .5
if mask_dir is not None:
mask = cv2.imread(str(mask_dir / name) + '.png')[:, :, 0]

valid_keypoint = mask[pred['keypoints'][:, 1].astype('int'), pred['keypoints'][:, 0].astype('int')]
pred['keypoints'] = pred['keypoints'][valid_keypoint > 0]
pred['descriptors'] = pred['descriptors'][:, valid_keypoint > 0]
pred['scores'] = pred['scores'][valid_keypoint > 0]
# add keypoint uncertainties scaled to the original resolution
uncertainty = getattr(model, 'detection_noise', 1) * scales.mean()



if as_half:
for k in pred:
dt = pred[k].dtype
Expand Down