Skip to content

Commit 355f84e

Browse files
authored
Fixed SG endpoint matching when there are no lines (cvg#7)
1 parent d732d5a commit 355f84e

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

limap/line2d/endpoints/extractor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
1010
import limap.util.io as limapio
1111

12+
1213
class SuperPointEndpointsExtractor(BaseDetector):
1314
def __init__(self, options = BaseDetectorOptions(), device=None):
1415
super(SuperPointEndpointsExtractor, self).__init__(options)
@@ -45,6 +46,11 @@ def compute_descinfo(self, img, segs):
4546
- the descriptor of each endpoints of shape [256, N*2]
4647
"""
4748
lines = segs[:, :4].reshape(-1, 2)
49+
if len(lines) == 0:
50+
return {
51+
'image_shape': img.shape, 'lines': lines,
52+
'lines_score': np.zeros((0,)),
53+
'endpoints_desc': np.zeros((256, 0))}
4854
scores = segs[:, -1] * np.sqrt(np.linalg.norm(segs[:, :2]
4955
- segs[:, 2:4], axis=1))
5056
scores /= np.amax(scores) + 1e-8
@@ -58,5 +64,3 @@ def compute_descinfo(self, img, segs):
5864
torch_img, torch_endpoints)['descriptors'][0].cpu().numpy()
5965
return {'image_shape': img.shape, 'lines': lines,
6066
'lines_score': scores, 'endpoints_desc': endpoint_descs}
61-
62-

limap/line2d/endpoints/matcher.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
1010
import limap.util.io as limapio
1111

12+
1213
class NNEndpointsMatcher(BaseMatcher):
1314
def __init__(self, extractor, options = BaseMatcherOptions(), device=None):
1415
super(NNEndpointsMatcher, self).__init__(extractor, options)
@@ -87,6 +88,7 @@ def match_segs_with_descinfo_topk(self, descinfo1, descinfo2, topk=10):
8788
matches.flatten()], axis=1)
8889
return matches_t
8990

91+
9092
class SuperGlueEndpointsMatcher(BaseMatcher):
9193
def __init__(self, extractor, options = BaseMatcherOptions(),
9294
weights='outdoor', device=None):
@@ -99,10 +101,13 @@ def get_module_name(self):
99101
return "superglue_endpoints"
100102

101103
def match_pair(self, descinfo1, descinfo2):
104+
if len(descinfo1['lines']) == 0 or len(descinfo1['lines']) == 0:
105+
return np.empty((0, 2))
102106
if self.topk == 0:
103107
return self.match_segs_with_descinfo(descinfo1, descinfo2)
104108
else:
105-
return self.match_segs_with_descinfo_topk(descinfo1, descinfo2, topk=self.topk)
109+
return self.match_segs_with_descinfo_topk(descinfo1, descinfo2,
110+
topk=self.topk)
106111

107112
def match_segs_with_descinfo(self, descinfo1, descinfo2):
108113
# Setup the inputs for SuperGlue
@@ -199,4 +204,3 @@ def match_segs_with_descinfo_topk(self, descinfo1, descinfo2, topk=10):
199204
matches_t = np.stack([np.arange(n_lines).repeat(topk),
200205
matches.flatten()], axis=1)
201206
return matches_t
202-

0 commit comments

Comments
 (0)