Skip to content

Commit

Permalink
Add image mask for mask out dynamic parts in the images for feature e…
Browse files Browse the repository at this point in the history
…xtraction. Copy the code from cvg#190
  • Loading branch information
lxxue committed Mar 29, 2023
1 parent 61e0cd0 commit e1d1c31
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hloc/extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ 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)}')

Expand All @@ -256,6 +257,14 @@ def main(conf: Dict,
name = dataset.names[idx]
pred = model({'image': data['image'].to(device, non_blocking=True)})
pred = {k: v[0].cpu().numpy() for k, v in pred.items()}
if mask_dir is not None:
mask_name = str(mask_dir / name) + '.png'
# print(mask_name)
mask = cv2.imread(mask_name)[:, :, 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]

pred['image_size'] = original_size = data['original_size'][0].numpy()
if 'keypoints' in pred:
Expand Down

0 comments on commit e1d1c31

Please sign in to comment.