MCPcopy Create free account
hub / github.com/ai4ce/RAP / match

Method match

matcher.py:120–196  ·  view source on GitHub ↗
(self, query, reference, conf_thr=-1, vis_fig=None)

Source from the content-addressed store, hash-verified

118 return valid_pts3d, matches_im_query, matches_im_map, matches_conf
119
120 def match(self, query, reference, conf_thr=-1, vis_fig=None):
121 if query.shape != reference.shape:
122 raise ValueError("Two images need to have the same shape.")
123
124 orig_h, orig_w = query.shape[1], query.shape[2]
125 images = convert_images([query, reference], size=512)
126 output = inference([tuple(images)], self.model, self.device, batch_size=1, verbose=False)
127
128 # at this stage, you have the raw dust3r predictions
129 view1, pred1 = output['view1'], output['pred1']
130 view2, pred2 = output['view2'], output['pred2']
131 conf1, conf2 = pred1['desc_conf'].squeeze(0).cpu().numpy(), pred2['desc_conf'].squeeze(0).cpu().numpy()
132 desc1, desc2 = pred1['desc'].squeeze(0).detach(), pred2['desc'].squeeze(0).detach()
133
134 # find 2D-2D matches between the two images
135 matches_im0, matches_im1 = fast_reciprocal_NNs(desc1, desc2, subsample_or_initxy1=8,
136 device=self.device, dist='dot', block_size=2**13)
137
138 # ignore small border around the edge
139 new_h, new_w = view1['true_shape'][0]
140 new_h = int(new_h)
141 new_w = int(new_w)
142 valid_matches_im0 = (matches_im0[:, 0] >= 3) & (matches_im0[:, 0] < new_w - 3) & (
143 matches_im0[:, 1] >= 3) & (matches_im0[:, 1] < new_h - 3)
144
145 valid_matches_im1 = (matches_im1[:, 0] >= 3) & (matches_im1[:, 0] < new_w - 3) & (
146 matches_im1[:, 1] >= 3) & (matches_im1[:, 1] < new_h - 3)
147
148 valid_matches = valid_matches_im0 & valid_matches_im1
149 matches_im0, matches_im1 = matches_im0[valid_matches], matches_im1[valid_matches]
150
151 if conf_thr >= 0:
152 matches_confs = np.minimum(
153 conf2[matches_im1[:, 1], matches_im1[:, 0]],
154 conf1[matches_im0[:, 1], matches_im0[:, 0]]
155 )
156 valid_matches = matches_confs >= conf_thr
157 matches_im0, matches_im1 = matches_im0[valid_matches], matches_im1[valid_matches]
158
159 if vis_fig is not None:
160 self.visualize_matches(view1, view2, matches_im0, matches_im1, vis_fig)
161
162 resize_func, to_resize, to_orig_1 = get_resize_function(self.maxdim,
163 self.model.patch_embed.patch_size,
164 orig_h, orig_w)
165
166 resize_func, to_resize, to_orig_2 = get_resize_function(self.maxdim,
167 self.model.patch_embed.patch_size,
168 orig_h, orig_w)
169
170 matches_im_query = matches_im0.astype(np.float64)
171 matches_im_map = matches_im1.astype(np.float64)
172
173 # if orig_h == new_h:
174 # if orig_w != new_w:
175 # matches_im_query[:, 0] += (orig_w - new_w) / 2
176 # matches_im_map[:, 0] += (orig_w - new_w) / 2
177 # else:

Callers 7

refineFunction · 0.95
match_coarse_to_fineMethod · 0.95
refineMethod · 0.80
refineMethod · 0.80
get_frame_numberFunction · 0.80
load_pfm_fileFunction · 0.80
_read_pfmFunction · 0.80

Calls 7

visualize_matchesMethod · 0.95
convert_imagesFunction · 0.90
inferenceFunction · 0.90
fast_reciprocal_NNsFunction · 0.90
get_resize_functionFunction · 0.90
geotrfFunction · 0.90
printFunction · 0.85

Tested by

no test coverage detected