keypoints_matching.py 940 B

12345678910111213141516171819202122232425262728293031
  1. """Thin wrapper around ``keypoints_on_match_image`` with cached correspondence."""
  2. from __future__ import annotations
  3. import sys
  4. from pathlib import Path
  5. _IMG_MATCH_DIR = Path(__file__).resolve().parent
  6. _REPO_ROOT = _IMG_MATCH_DIR.parent
  7. for _p in (_REPO_ROOT, _IMG_MATCH_DIR):
  8. if str(_p) not in sys.path:
  9. sys.path.insert(0, str(_p))
  10. import numpy as np
  11. from keypoints_on_match_image import gather_correspondence
  12. class KeypointsMatching:
  13. def __init__(self, keypoints_obj):
  14. self.keypoints_obj = keypoints_obj
  15. self._correspondence: dict | None = None
  16. def correspondence(self) -> dict:
  17. if self._correspondence is None:
  18. self._correspondence = gather_correspondence(self.keypoints_obj)
  19. return self._correspondence
  20. def get_keypoints(self) -> np.ndarray:
  21. xy = self.correspondence()["matched_keypoints_original_xy"]
  22. return np.asarray(xy, dtype=np.float64)