@@ -107,6 +107,41 @@ void MapClosures::MatchAndAddToDatabase(const int id,
107107 ground_alignments_.emplace (id, T_ground);
108108}
109109
110+ void MapClosures::Match (const std::vector<Eigen::Vector3d> &local_map) {
111+ const Eigen::Matrix4d T_ground = AlignToLocalGround (local_map, config_.density_map_resolution );
112+ DensityMap density_map = GenerateDensityMap (local_map, T_ground, config_.density_map_resolution ,
113+ config_.density_threshold );
114+ cv::Mat orb_descriptors;
115+ std::vector<cv::KeyPoint> orb_keypoints;
116+ orb_keypoints.reserve (nfeatures);
117+ orb_extractor_->detectAndCompute (density_map.grid , cv::noArray (), orb_keypoints,
118+ orb_descriptors);
119+ orb_keypoints.shrink_to_fit ();
120+
121+ const auto self_matcher = cv::BFMatcher (cv::NORM_HAMMING);
122+ std::vector<std::vector<cv::DMatch>> self_matches;
123+ self_matches.reserve (orb_keypoints.size ());
124+ self_matcher.knnMatch (orb_descriptors, orb_descriptors, self_matches, 2 );
125+
126+ std::vector<Matchable *> hbst_matchable;
127+ hbst_matchable.reserve (orb_descriptors.rows );
128+ std::for_each (
129+ self_matches.cbegin (), self_matches.cend (), [&](const std::vector<cv::DMatch> &self_match) {
130+ if (self_match[1 ].distance > self_similarity_threshold) {
131+ const auto index_descriptor = self_match[0 ].queryIdx ;
132+ cv::KeyPoint &keypoint = orb_keypoints[index_descriptor];
133+ keypoint.pt .x = keypoint.pt .x + static_cast <float >(density_map.lower_bound .y ());
134+ keypoint.pt .y = keypoint.pt .y + static_cast <float >(density_map.lower_bound .x ());
135+ hbst_matchable.emplace_back (
136+ new Matchable (keypoint, orb_descriptors.row (index_descriptor)));
137+ }
138+ });
139+ hbst_matchable.shrink_to_fit ();
140+
141+ hbst_binary_tree_->match (hbst_matchable, descriptor_matches_,
142+ config_.hamming_distance_threshold );
143+ }
144+
110145ClosureCandidate MapClosures::ValidateClosure (const int reference_id, const int query_id) const {
111146 const auto it = descriptor_matches_.find (reference_id);
112147 if (it == descriptor_matches_.end ()) {
0 commit comments