Spaces:
Runtime error
Runtime error
add: GIM (https://github.com/xuelunshen/gim)
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- common/config.yaml +23 -1
- common/utils.py +50 -23
- common/viz.py +35 -34
- datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot135.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot180.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot225.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot270.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot315.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot45.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot90.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot135.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot180.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot225.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot270.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot315.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot45.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot90.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot135.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot180.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot225.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot270.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot315.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot45.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot90.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot135.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot180.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot225.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot270.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot315.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot45.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot90.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot135.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot180.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot225.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot270.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot315.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot45.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot90.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot135.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot180.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot225.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot270.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot315.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot45.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot90.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot135.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot180.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot225.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot270.jpg +3 -0
- datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot315.jpg +3 -0
common/config.yaml
CHANGED
|
@@ -16,7 +16,29 @@ defaults:
|
|
| 16 |
setting_geometry: Homography
|
| 17 |
|
| 18 |
matcher_zoo:
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
matcher: roma
|
| 21 |
dense: true
|
| 22 |
info:
|
|
|
|
| 16 |
setting_geometry: Homography
|
| 17 |
|
| 18 |
matcher_zoo:
|
| 19 |
+
DUSt3R:
|
| 20 |
+
# TODO: duster is under development
|
| 21 |
+
enable: false
|
| 22 |
+
matcher: duster
|
| 23 |
+
dense: true
|
| 24 |
+
info:
|
| 25 |
+
name: DUSt3R #dispaly name
|
| 26 |
+
source: "CVPR 2024"
|
| 27 |
+
github: https://github.com/naver/dust3r
|
| 28 |
+
paper: https://arxiv.org/abs/2312.14132
|
| 29 |
+
project: https://dust3r.europe.naverlabs.com
|
| 30 |
+
display: true
|
| 31 |
+
GIM(dkm):
|
| 32 |
+
matcher: gim(dkm)
|
| 33 |
+
dense: true
|
| 34 |
+
info:
|
| 35 |
+
name: GIM(DKM) #dispaly name
|
| 36 |
+
source: "ICLR 2024"
|
| 37 |
+
github: https://github.com/xuelunshen/gim
|
| 38 |
+
paper: https://arxiv.org/abs/2402.11095
|
| 39 |
+
project: https://xuelunshen.com/gim
|
| 40 |
+
display: true
|
| 41 |
+
RoMa:
|
| 42 |
matcher: roma
|
| 43 |
dense: true
|
| 44 |
info:
|
common/utils.py
CHANGED
|
@@ -10,11 +10,11 @@ from typing import Callable, Dict, Any, Optional, Tuple, List, Union
|
|
| 10 |
from hloc import matchers, extractors, logger
|
| 11 |
from hloc.utils.base_model import dynamic_load
|
| 12 |
from hloc import match_dense, match_features, extract_features
|
| 13 |
-
from hloc.utils.viz import add_text, plot_keypoints
|
| 14 |
from .viz import (
|
| 15 |
fig2im,
|
| 16 |
plot_images,
|
| 17 |
display_matches,
|
|
|
|
| 18 |
plot_color_line_matches,
|
| 19 |
)
|
| 20 |
import time
|
|
@@ -131,7 +131,7 @@ def gen_examples():
|
|
| 131 |
"dedode",
|
| 132 |
"loftr",
|
| 133 |
"disk",
|
| 134 |
-
"
|
| 135 |
"d2net",
|
| 136 |
"aspanformer",
|
| 137 |
"topicfm",
|
|
@@ -148,6 +148,7 @@ def gen_examples():
|
|
| 148 |
np.random.shuffle(new_B)
|
| 149 |
return new_B.tolist()
|
| 150 |
|
|
|
|
| 151 |
def gen_images_pairs(count: int = 5):
|
| 152 |
path = str(ROOT / "datasets/sacre_coeur/mapping")
|
| 153 |
imgs_list = [
|
|
@@ -156,9 +157,34 @@ def gen_examples():
|
|
| 156 |
if file.lower().endswith((".jpg", ".jpeg", ".png"))
|
| 157 |
]
|
| 158 |
pairs = list(combinations(imgs_list, 2))
|
|
|
|
|
|
|
| 159 |
selected = random.sample(range(len(pairs)), count)
|
| 160 |
return [pairs[i] for i in selected]
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
def gen_image_pairs_wxbs(count: int = None):
|
| 163 |
prefix = "datasets/wxbs_benchmark/.WxBS/v1.1"
|
| 164 |
wxbs_path = ROOT / prefix
|
|
@@ -179,6 +205,7 @@ def gen_examples():
|
|
| 179 |
|
| 180 |
# image pair path
|
| 181 |
pairs = gen_images_pairs()
|
|
|
|
| 182 |
pairs += gen_image_pairs_wxbs()
|
| 183 |
|
| 184 |
match_setting_threshold = DEFAULT_SETTING_THRESHOLD
|
|
@@ -211,8 +238,8 @@ def gen_examples():
|
|
| 211 |
|
| 212 |
def set_null_pred(feature_type: str, pred: dict):
|
| 213 |
if feature_type == "KEYPOINT":
|
| 214 |
-
pred["
|
| 215 |
-
pred["
|
| 216 |
pred["mmconf"] = np.array([])
|
| 217 |
elif feature_type == "LINE":
|
| 218 |
pred["mline_keypoints0_orig"] = np.array([])
|
|
@@ -246,9 +273,9 @@ def filter_matches(
|
|
| 246 |
mkpts0: Optional[np.ndarray] = None
|
| 247 |
mkpts1: Optional[np.ndarray] = None
|
| 248 |
feature_type: Optional[str] = None
|
| 249 |
-
if "
|
| 250 |
-
mkpts0 = pred["
|
| 251 |
-
mkpts1 = pred["
|
| 252 |
feature_type = "KEYPOINT"
|
| 253 |
elif (
|
| 254 |
"line_keypoints0_orig" in pred.keys()
|
|
@@ -277,8 +304,8 @@ def filter_matches(
|
|
| 277 |
mask = np.array(mask.ravel().astype("bool"), dtype="bool")
|
| 278 |
if H is not None:
|
| 279 |
if feature_type == "KEYPOINT":
|
| 280 |
-
pred["
|
| 281 |
-
pred["
|
| 282 |
pred["mmconf"] = pred["mconf"][mask]
|
| 283 |
elif feature_type == "LINE":
|
| 284 |
pred["mline_keypoints0_orig"] = mkpts0[mask]
|
|
@@ -313,9 +340,9 @@ def compute_geometry(
|
|
| 313 |
mkpts0: Optional[np.ndarray] = None
|
| 314 |
mkpts1: Optional[np.ndarray] = None
|
| 315 |
|
| 316 |
-
if "
|
| 317 |
-
mkpts0 = pred["
|
| 318 |
-
mkpts1 = pred["
|
| 319 |
elif (
|
| 320 |
"line_keypoints0_orig" in pred.keys()
|
| 321 |
and "line_keypoints1_orig" in pred.keys()
|
|
@@ -654,27 +681,19 @@ def run_matching(
|
|
| 654 |
)
|
| 655 |
logger.info(f"Matching images done using: {time.time()-t1:.3f}s")
|
| 656 |
t1 = time.time()
|
| 657 |
-
|
|
|
|
| 658 |
titles = [
|
| 659 |
"Image 0 - Keypoints",
|
| 660 |
"Image 1 - Keypoints",
|
| 661 |
]
|
| 662 |
-
output_keypoints =
|
| 663 |
-
if "keypoints0" in pred.keys() and "keypoints1" in pred.keys():
|
| 664 |
-
plot_keypoints([pred["keypoints0"], pred["keypoints1"]])
|
| 665 |
-
text = (
|
| 666 |
-
f"# keypoints0: {len(pred['keypoints0'])} \n"
|
| 667 |
-
+ f"# keypoints1: {len(pred['keypoints1'])}"
|
| 668 |
-
)
|
| 669 |
-
add_text(0, text, fs=15)
|
| 670 |
-
output_keypoints = fig2im(output_keypoints)
|
| 671 |
|
| 672 |
# plot images with raw matches
|
| 673 |
titles = [
|
| 674 |
"Image 0 - Raw matched keypoints",
|
| 675 |
"Image 1 - Raw matched keypoints",
|
| 676 |
]
|
| 677 |
-
|
| 678 |
output_matches_raw, num_matches_raw = display_matches(pred, titles=titles)
|
| 679 |
|
| 680 |
# if enable_ransac:
|
|
@@ -755,3 +774,11 @@ ransac_zoo = {
|
|
| 755 |
"USAC_ACCURATE": cv2.USAC_ACCURATE,
|
| 756 |
"USAC_PARALLEL": cv2.USAC_PARALLEL,
|
| 757 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
from hloc import matchers, extractors, logger
|
| 11 |
from hloc.utils.base_model import dynamic_load
|
| 12 |
from hloc import match_dense, match_features, extract_features
|
|
|
|
| 13 |
from .viz import (
|
| 14 |
fig2im,
|
| 15 |
plot_images,
|
| 16 |
display_matches,
|
| 17 |
+
display_keypoints,
|
| 18 |
plot_color_line_matches,
|
| 19 |
)
|
| 20 |
import time
|
|
|
|
| 131 |
"dedode",
|
| 132 |
"loftr",
|
| 133 |
"disk",
|
| 134 |
+
"RoMa",
|
| 135 |
"d2net",
|
| 136 |
"aspanformer",
|
| 137 |
"topicfm",
|
|
|
|
| 148 |
np.random.shuffle(new_B)
|
| 149 |
return new_B.tolist()
|
| 150 |
|
| 151 |
+
# normal examples
|
| 152 |
def gen_images_pairs(count: int = 5):
|
| 153 |
path = str(ROOT / "datasets/sacre_coeur/mapping")
|
| 154 |
imgs_list = [
|
|
|
|
| 157 |
if file.lower().endswith((".jpg", ".jpeg", ".png"))
|
| 158 |
]
|
| 159 |
pairs = list(combinations(imgs_list, 2))
|
| 160 |
+
if len(pairs) < count:
|
| 161 |
+
count = len(pairs)
|
| 162 |
selected = random.sample(range(len(pairs)), count)
|
| 163 |
return [pairs[i] for i in selected]
|
| 164 |
|
| 165 |
+
# rotated examples
|
| 166 |
+
def gen_rot_image_pairs(count: int = 5):
|
| 167 |
+
path = ROOT / "datasets/sacre_coeur/mapping"
|
| 168 |
+
path_rot = ROOT / "datasets/sacre_coeur/mapping_rot"
|
| 169 |
+
rot_list = [45, 90, 135, 180, 225, 270]
|
| 170 |
+
pairs = []
|
| 171 |
+
for file in os.listdir(path):
|
| 172 |
+
if file.lower().endswith((".jpg", ".jpeg", ".png")):
|
| 173 |
+
for rot in rot_list:
|
| 174 |
+
file_rot = "{}_rot{}.jpg".format(Path(file).stem, rot)
|
| 175 |
+
if (path_rot / file_rot).exists():
|
| 176 |
+
pairs.append(
|
| 177 |
+
[
|
| 178 |
+
path / file,
|
| 179 |
+
path_rot / file_rot,
|
| 180 |
+
]
|
| 181 |
+
)
|
| 182 |
+
if len(pairs) < count:
|
| 183 |
+
count = len(pairs)
|
| 184 |
+
selected = random.sample(range(len(pairs)), count)
|
| 185 |
+
return [pairs[i] for i in selected]
|
| 186 |
+
|
| 187 |
+
# extramely hard examples
|
| 188 |
def gen_image_pairs_wxbs(count: int = None):
|
| 189 |
prefix = "datasets/wxbs_benchmark/.WxBS/v1.1"
|
| 190 |
wxbs_path = ROOT / prefix
|
|
|
|
| 205 |
|
| 206 |
# image pair path
|
| 207 |
pairs = gen_images_pairs()
|
| 208 |
+
pairs += gen_rot_image_pairs()
|
| 209 |
pairs += gen_image_pairs_wxbs()
|
| 210 |
|
| 211 |
match_setting_threshold = DEFAULT_SETTING_THRESHOLD
|
|
|
|
| 238 |
|
| 239 |
def set_null_pred(feature_type: str, pred: dict):
|
| 240 |
if feature_type == "KEYPOINT":
|
| 241 |
+
pred["mmkeypoints0_orig"] = np.array([])
|
| 242 |
+
pred["mmkeypoints1_orig"] = np.array([])
|
| 243 |
pred["mmconf"] = np.array([])
|
| 244 |
elif feature_type == "LINE":
|
| 245 |
pred["mline_keypoints0_orig"] = np.array([])
|
|
|
|
| 273 |
mkpts0: Optional[np.ndarray] = None
|
| 274 |
mkpts1: Optional[np.ndarray] = None
|
| 275 |
feature_type: Optional[str] = None
|
| 276 |
+
if "mkeypoints0_orig" in pred.keys() and "mkeypoints1_orig" in pred.keys():
|
| 277 |
+
mkpts0 = pred["mkeypoints0_orig"]
|
| 278 |
+
mkpts1 = pred["mkeypoints1_orig"]
|
| 279 |
feature_type = "KEYPOINT"
|
| 280 |
elif (
|
| 281 |
"line_keypoints0_orig" in pred.keys()
|
|
|
|
| 304 |
mask = np.array(mask.ravel().astype("bool"), dtype="bool")
|
| 305 |
if H is not None:
|
| 306 |
if feature_type == "KEYPOINT":
|
| 307 |
+
pred["mmkeypoints0_orig"] = mkpts0[mask]
|
| 308 |
+
pred["mmkeypoints1_orig"] = mkpts1[mask]
|
| 309 |
pred["mmconf"] = pred["mconf"][mask]
|
| 310 |
elif feature_type == "LINE":
|
| 311 |
pred["mline_keypoints0_orig"] = mkpts0[mask]
|
|
|
|
| 340 |
mkpts0: Optional[np.ndarray] = None
|
| 341 |
mkpts1: Optional[np.ndarray] = None
|
| 342 |
|
| 343 |
+
if "mkeypoints0_orig" in pred.keys() and "mkeypoints1_orig" in pred.keys():
|
| 344 |
+
mkpts0 = pred["mkeypoints0_orig"]
|
| 345 |
+
mkpts1 = pred["mkeypoints1_orig"]
|
| 346 |
elif (
|
| 347 |
"line_keypoints0_orig" in pred.keys()
|
| 348 |
and "line_keypoints1_orig" in pred.keys()
|
|
|
|
| 681 |
)
|
| 682 |
logger.info(f"Matching images done using: {time.time()-t1:.3f}s")
|
| 683 |
t1 = time.time()
|
| 684 |
+
|
| 685 |
+
# plot images with keypoints
|
| 686 |
titles = [
|
| 687 |
"Image 0 - Keypoints",
|
| 688 |
"Image 1 - Keypoints",
|
| 689 |
]
|
| 690 |
+
output_keypoints = display_keypoints(pred, titles=titles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
|
| 692 |
# plot images with raw matches
|
| 693 |
titles = [
|
| 694 |
"Image 0 - Raw matched keypoints",
|
| 695 |
"Image 1 - Raw matched keypoints",
|
| 696 |
]
|
|
|
|
| 697 |
output_matches_raw, num_matches_raw = display_matches(pred, titles=titles)
|
| 698 |
|
| 699 |
# if enable_ransac:
|
|
|
|
| 774 |
"USAC_ACCURATE": cv2.USAC_ACCURATE,
|
| 775 |
"USAC_PARALLEL": cv2.USAC_PARALLEL,
|
| 776 |
}
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
def rotate_image(input_path, degrees, output_path):
|
| 780 |
+
from PIL import Image
|
| 781 |
+
|
| 782 |
+
img = Image.open(input_path)
|
| 783 |
+
img_rotated = img.rotate(-degrees)
|
| 784 |
+
img_rotated.save(output_path)
|
common/viz.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
import cv2
|
|
|
|
| 2 |
import matplotlib
|
| 3 |
import numpy as np
|
| 4 |
import seaborn as sns
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
from pathlib import Path
|
| 7 |
-
import typing
|
| 8 |
from typing import Dict, Any, Optional, Tuple, List, Union
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def plot_images(
|
|
@@ -376,6 +377,21 @@ def draw_image_pairs(
|
|
| 376 |
return fig2im(fig)
|
| 377 |
|
| 378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
def display_matches(
|
| 380 |
pred: Dict[str, np.ndarray],
|
| 381 |
titles: List[str] = [],
|
|
@@ -397,41 +413,26 @@ def display_matches(
|
|
| 397 |
img0 = pred["image0_orig"]
|
| 398 |
img1 = pred["image1_orig"]
|
| 399 |
num_inliers = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
# draw raw matches
|
| 401 |
if (
|
| 402 |
-
|
| 403 |
-
and
|
| 404 |
-
and pred[
|
| 405 |
-
and pred[
|
| 406 |
-
and tag == "KPTS_RAW"
|
| 407 |
-
):
|
| 408 |
-
mkpts0 = pred["keypoints0_orig"]
|
| 409 |
-
mkpts1 = pred["keypoints1_orig"]
|
| 410 |
-
num_inliers = len(mkpts0)
|
| 411 |
-
if "mconf" in pred:
|
| 412 |
-
mconf = pred["mconf"]
|
| 413 |
-
else:
|
| 414 |
-
mconf = np.ones(len(mkpts0))
|
| 415 |
-
fig_mkpts = draw_matches_core(
|
| 416 |
-
mkpts0,
|
| 417 |
-
mkpts1,
|
| 418 |
-
img0,
|
| 419 |
-
img1,
|
| 420 |
-
mconf,
|
| 421 |
-
dpi=dpi,
|
| 422 |
-
titles=titles,
|
| 423 |
-
texts=texts,
|
| 424 |
-
)
|
| 425 |
-
fig = fig_mkpts
|
| 426 |
-
elif (
|
| 427 |
-
"mkeypoints0_orig" in pred
|
| 428 |
-
and "mkeypoints1_orig" in pred
|
| 429 |
-
and pred["mkeypoints0_orig"] is not None
|
| 430 |
-
and pred["mkeypoints1_orig"] is not None
|
| 431 |
-
and tag == "KPTS_RANSAC"
|
| 432 |
): # draw ransac matches
|
| 433 |
-
mkpts0 = pred[
|
| 434 |
-
mkpts1 = pred[
|
| 435 |
num_inliers = len(mkpts0)
|
| 436 |
if "mmconf" in pred:
|
| 437 |
mmconf = pred["mmconf"]
|
|
@@ -454,7 +455,7 @@ def display_matches(
|
|
| 454 |
and "line1_orig" in pred
|
| 455 |
and pred["line0_orig"] is not None
|
| 456 |
and pred["line1_orig"] is not None
|
| 457 |
-
|
| 458 |
):
|
| 459 |
# lines
|
| 460 |
mtlines0 = pred["line0_orig"]
|
|
|
|
| 1 |
import cv2
|
| 2 |
+
import typing
|
| 3 |
import matplotlib
|
| 4 |
import numpy as np
|
| 5 |
import seaborn as sns
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
from pathlib import Path
|
|
|
|
| 8 |
from typing import Dict, Any, Optional, Tuple, List, Union
|
| 9 |
+
from hloc.utils.viz import add_text, plot_keypoints
|
| 10 |
|
| 11 |
|
| 12 |
def plot_images(
|
|
|
|
| 377 |
return fig2im(fig)
|
| 378 |
|
| 379 |
|
| 380 |
+
def display_keypoints(pred: dict, titles: List[str] = []):
|
| 381 |
+
img0 = pred["image0_orig"]
|
| 382 |
+
img1 = pred["image1_orig"]
|
| 383 |
+
output_keypoints = plot_images([img0, img1], titles=titles, dpi=300)
|
| 384 |
+
if "keypoints0_orig" in pred.keys() and "keypoints1_orig" in pred.keys():
|
| 385 |
+
plot_keypoints([pred["keypoints0_orig"], pred["keypoints1_orig"]])
|
| 386 |
+
text = (
|
| 387 |
+
f"# keypoints0: {len(pred['keypoints0_orig'])} \n"
|
| 388 |
+
+ f"# keypoints1: {len(pred['keypoints1_orig'])}"
|
| 389 |
+
)
|
| 390 |
+
add_text(0, text, fs=15)
|
| 391 |
+
output_keypoints = fig2im(output_keypoints)
|
| 392 |
+
return output_keypoints
|
| 393 |
+
|
| 394 |
+
|
| 395 |
def display_matches(
|
| 396 |
pred: Dict[str, np.ndarray],
|
| 397 |
titles: List[str] = [],
|
|
|
|
| 413 |
img0 = pred["image0_orig"]
|
| 414 |
img1 = pred["image1_orig"]
|
| 415 |
num_inliers = 0
|
| 416 |
+
KPTS0_KEY = None
|
| 417 |
+
KPTS1_KEY = None
|
| 418 |
+
if tag == "KPTS_RAW":
|
| 419 |
+
KPTS0_KEY = "mkeypoints0_orig"
|
| 420 |
+
KPTS1_KEY = "mkeypoints1_orig"
|
| 421 |
+
elif tag == "KPTS_RANSAC":
|
| 422 |
+
KPTS0_KEY = "mmkeypoints0_orig"
|
| 423 |
+
KPTS1_KEY = "mmkeypoints1_orig"
|
| 424 |
+
else:
|
| 425 |
+
# TODO: LINES_RAW, LINES_RANSAC
|
| 426 |
+
raise ValueError(f"Unknown tag: {tag}")
|
| 427 |
# draw raw matches
|
| 428 |
if (
|
| 429 |
+
KPTS0_KEY in pred
|
| 430 |
+
and KPTS1_KEY in pred
|
| 431 |
+
and pred[KPTS0_KEY] is not None
|
| 432 |
+
and pred[KPTS1_KEY] is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
): # draw ransac matches
|
| 434 |
+
mkpts0 = pred[KPTS0_KEY]
|
| 435 |
+
mkpts1 = pred[KPTS1_KEY]
|
| 436 |
num_inliers = len(mkpts0)
|
| 437 |
if "mmconf" in pred:
|
| 438 |
mmconf = pred["mmconf"]
|
|
|
|
| 455 |
and "line1_orig" in pred
|
| 456 |
and pred["line0_orig"] is not None
|
| 457 |
and pred["line1_orig"] is not None
|
| 458 |
+
and (tag == "LINES_RAW" or tag == "LINES_RANSAC")
|
| 459 |
):
|
| 460 |
# lines
|
| 461 |
mtlines0 = pred["line0_orig"]
|
datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot135.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot180.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot225.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot270.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot315.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot45.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/02928139_3448003521_rot90.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot135.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot180.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot225.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot270.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot315.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot45.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/03903474_1471484089_rot90.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot135.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot180.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot225.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot270.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot315.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot45.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/10265353_3838484249_rot90.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot135.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot180.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot225.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot270.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot315.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot45.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/17295357_9106075285_rot90.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot135.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot180.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot225.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot270.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot315.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot45.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/32809961_8274055477_rot90.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot135.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot180.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot225.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot270.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot315.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot45.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/44120379_8371960244_rot90.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot135.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot180.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot225.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot270.jpg
ADDED
|
Git LFS Details
|
datasets/sacre_coeur/mapping_rot/51091044_3486849416_rot315.jpg
ADDED
|
Git LFS Details
|