Spaces:
Running
Running
Vincentqyw
commited on
Commit
•
8869f68
1
Parent(s):
8e76240
update: d2net model links and SIFT
Browse files- common/utils.py +12 -9
- hloc/extractors/d2net.py +1 -1
- hloc/extractors/dog.py +6 -4
common/utils.py
CHANGED
@@ -5,7 +5,7 @@ import torch
|
|
5 |
from itertools import combinations
|
6 |
import cv2
|
7 |
import gradio as gr
|
8 |
-
from hloc import matchers, extractors
|
9 |
from hloc.utils.base_model import dynamic_load
|
10 |
from hloc import match_dense, match_features, extract_features
|
11 |
from hloc.utils.viz import add_text, plot_keypoints
|
@@ -187,14 +187,17 @@ def compute_geom(
|
|
187 |
)
|
188 |
if H is not None:
|
189 |
geo_info["Homography"] = H.tolist()
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
198 |
return geo_info
|
199 |
else:
|
200 |
return {}
|
|
|
5 |
from itertools import combinations
|
6 |
import cv2
|
7 |
import gradio as gr
|
8 |
+
from hloc import matchers, extractors, logger
|
9 |
from hloc.utils.base_model import dynamic_load
|
10 |
from hloc import match_dense, match_features, extract_features
|
11 |
from hloc.utils.viz import add_text, plot_keypoints
|
|
|
187 |
)
|
188 |
if H is not None:
|
189 |
geo_info["Homography"] = H.tolist()
|
190 |
+
try:
|
191 |
+
_, H1, H2 = cv2.stereoRectifyUncalibrated(
|
192 |
+
mkpts0.reshape(-1, 2),
|
193 |
+
mkpts1.reshape(-1, 2),
|
194 |
+
F,
|
195 |
+
imgSize=(w1, h1),
|
196 |
+
)
|
197 |
+
geo_info["H1"] = H1.tolist()
|
198 |
+
geo_info["H2"] = H2.tolist()
|
199 |
+
except cv2.error as e:
|
200 |
+
logger.error(f"e, skip")
|
201 |
return geo_info
|
202 |
else:
|
203 |
return {}
|
hloc/extractors/d2net.py
CHANGED
@@ -26,7 +26,7 @@ class D2Net(BaseModel):
|
|
26 |
model_file.parent.mkdir(exist_ok=True)
|
27 |
cmd = [
|
28 |
"wget",
|
29 |
-
"https://
|
30 |
"-O",
|
31 |
str(model_file),
|
32 |
]
|
|
|
26 |
model_file.parent.mkdir(exist_ok=True)
|
27 |
cmd = [
|
28 |
"wget",
|
29 |
+
"https://dusmanu.com/files/d2-net/" + conf["model_name"],
|
30 |
"-O",
|
31 |
str(model_file),
|
32 |
]
|
hloc/extractors/dog.py
CHANGED
@@ -44,6 +44,7 @@ class DoG(BaseModel):
|
|
44 |
raise ValueError(f'Unknown descriptor: {conf["descriptor"]}')
|
45 |
|
46 |
self.sift = None # lazily instantiated on the first image
|
|
|
47 |
self.device = torch.device("cpu")
|
48 |
|
49 |
def to(self, *args, **kwargs):
|
@@ -63,7 +64,8 @@ class DoG(BaseModel):
|
|
63 |
assert image_np.min() >= -EPS and image_np.max() <= 1 + EPS
|
64 |
|
65 |
if self.sift is None:
|
66 |
-
|
|
|
67 |
options = {**self.conf["options"]}
|
68 |
if self.conf["descriptor"] == "rootsift":
|
69 |
options["normalization"] = pycolmap.Normalization.L1_ROOT
|
@@ -73,8 +75,7 @@ class DoG(BaseModel):
|
|
73 |
options=pycolmap.SiftExtractionOptions(options),
|
74 |
device=getattr(pycolmap.Device, "cuda" if use_gpu else "cpu"),
|
75 |
)
|
76 |
-
|
77 |
-
keypoints, scores, descriptors = self.sift.extract(image_np)
|
78 |
scales = keypoints[:, 2]
|
79 |
oris = np.rad2deg(keypoints[:, 3])
|
80 |
|
@@ -109,7 +110,8 @@ class DoG(BaseModel):
|
|
109 |
keypoints = torch.from_numpy(keypoints[:, :2]) # keep only x, y
|
110 |
scales = torch.from_numpy(scales)
|
111 |
oris = torch.from_numpy(oris)
|
112 |
-
scores =
|
|
|
113 |
if self.conf["max_keypoints"] != -1:
|
114 |
# TODO: check that the scores from PyCOLMAP are 100% correct,
|
115 |
# follow https://github.com/mihaidusmanu/pycolmap/issues/8
|
|
|
44 |
raise ValueError(f'Unknown descriptor: {conf["descriptor"]}')
|
45 |
|
46 |
self.sift = None # lazily instantiated on the first image
|
47 |
+
self.dummy_param = torch.nn.Parameter(torch.empty(0))
|
48 |
self.device = torch.device("cpu")
|
49 |
|
50 |
def to(self, *args, **kwargs):
|
|
|
64 |
assert image_np.min() >= -EPS and image_np.max() <= 1 + EPS
|
65 |
|
66 |
if self.sift is None:
|
67 |
+
device = self.dummy_param.device
|
68 |
+
use_gpu = pycolmap.has_cuda and device.type == "cuda"
|
69 |
options = {**self.conf["options"]}
|
70 |
if self.conf["descriptor"] == "rootsift":
|
71 |
options["normalization"] = pycolmap.Normalization.L1_ROOT
|
|
|
75 |
options=pycolmap.SiftExtractionOptions(options),
|
76 |
device=getattr(pycolmap.Device, "cuda" if use_gpu else "cpu"),
|
77 |
)
|
78 |
+
keypoints, descriptors = self.sift.extract(image_np)
|
|
|
79 |
scales = keypoints[:, 2]
|
80 |
oris = np.rad2deg(keypoints[:, 3])
|
81 |
|
|
|
110 |
keypoints = torch.from_numpy(keypoints[:, :2]) # keep only x, y
|
111 |
scales = torch.from_numpy(scales)
|
112 |
oris = torch.from_numpy(oris)
|
113 |
+
scores = keypoints.new_zeros(len(keypoints)) # no scores for SIFT yet
|
114 |
+
|
115 |
if self.conf["max_keypoints"] != -1:
|
116 |
# TODO: check that the scores from PyCOLMAP are 100% correct,
|
117 |
# follow https://github.com/mihaidusmanu/pycolmap/issues/8
|