1 import cslam.lidar_pr.scancontext_utils
as sc_utils
3 from scipy
import spatial
6 """Nearest Neighbor matching of description vectors
9 def __init__(self, shape=[20,60], num_candidates=10, threshold=0.15):
11 Default configs are the same as in the original paper
24 """Add item to the matching list
27 descriptor (np.array): descriptor
28 item: identification info (e.g., int)
30 sc = descriptor.reshape(self.
shapeshape)
38 rk = sc_utils.sc2rk(sc)
47 """Search for nearest neighbors
50 query (np.array): descriptor to match
51 k (int): number of best matches to return
54 list(int, np.array): best matches
61 ringkey_tree = spatial.KDTree(ringkey_history)
63 query_sc = query.reshape(self.
shapeshape)
64 ringkey_query = sc_utils.sc2rk(query_sc)
65 _, nncandidates_idx = ringkey_tree.query(ringkey_query, k=self.
num_candidatesnum_candidates)
72 candidate_idx = nncandidates_idx[ith]
73 candidate_sc = self.
scancontextsscancontexts[candidate_idx]
74 dist, yaw_diff = sc_utils.distance_sc(candidate_sc, query_sc)
78 nn_idx = candidate_idx
85 nn_yawdiff_deg = nn_yawdiff * (360/self.
shapeshape[1])
86 similarity = 1 - nn_dist
87 return [self.
itemsitems[nn_idx]], [similarity]
90 """Search for the nearest neighbor
91 Implementation for compatibily only
94 query (np.array): descriptor to match
97 int, np.array: best match
102 idxs, sims = self.
searchsearch(query, 1)
104 return idxs[0], sims[0]
def search_best(self, query)
def __init__(self, shape=[20, 60], num_candidates=10, threshold=0.15)
def add_item(self, descriptor, item)
def search(self, query, k)