@@ -67,7 +67,8 @@ MapClosures::MapClosures(const Config &config) : config_(config) {
6767 cv::ORB::ScoreType (score_type), patch_size, fast_threshold);
6868}
6969
70- void MapClosures::MatchAndAdd (const int id, const std::vector<Eigen::Vector3d> &local_map) {
70+ void MapClosures::MatchAndAddToDatabase (const int id,
71+ const std::vector<Eigen::Vector3d> &local_map) {
7172 Eigen::Matrix4d T_ground = AlignToLocalGround (local_map, ground_alignment_resolution);
7273 DensityMap density_map = GenerateDensityMap (local_map, T_ground, config_.density_map_resolution ,
7374 config_.density_threshold );
@@ -104,9 +105,37 @@ void MapClosures::MatchAndAdd(const int id, const std::vector<Eigen::Vector3d> &
104105 srrg_hbst::SplittingStrategy::SplitEven);
105106}
106107
108+ ClosureCandidate MapClosures::ValidateClosure (const int reference_id, const int query_id) const {
109+ const Tree::MatchVector &matches = descriptor_matches_.at (reference_id);
110+ const size_t num_matches = matches.size ();
111+
112+ ClosureCandidate closure;
113+ if (num_matches > min_no_of_matches) {
114+ std::vector<PointPair> keypoint_pairs (num_matches);
115+ std::transform (matches.cbegin (), matches.cend (), keypoint_pairs.begin (),
116+ [&](const Tree::Match &match) {
117+ auto query_point =
118+ Eigen::Vector2d (match.object_query .pt .y , match.object_query .pt .x );
119+ auto ref_point = Eigen::Vector2d (match.object_references [0 ].pt .y ,
120+ match.object_references [0 ].pt .x );
121+ return PointPair (ref_point, query_point);
122+ });
123+
124+ const auto &[pose2d, number_of_inliers] = RansacAlignment2D (keypoint_pairs);
125+ closure.source_id = reference_id;
126+ closure.target_id = query_id;
127+ closure.pose .block <2 , 2 >(0 , 0 ) = pose2d.linear ();
128+ closure.pose .block <2 , 1 >(0 , 3 ) = pose2d.translation () * config_.density_map_resolution ;
129+ closure.pose = ground_alignments_.at (query_id).inverse () * closure.pose *
130+ ground_alignments_.at (reference_id);
131+ closure.number_of_inliers = number_of_inliers;
132+ }
133+ return closure;
134+ }
135+
107136ClosureCandidate MapClosures::GetBestClosure (const int query_id,
108137 const std::vector<Eigen::Vector3d> &local_map) {
109- MatchAndAdd (query_id, local_map);
138+ MatchAndAddToDatabase (query_id, local_map);
110139 auto compare_closure_candidates = [](ClosureCandidate a,
111140 const ClosureCandidate &b) -> ClosureCandidate {
112141 return a.number_of_inliers > b.number_of_inliers ? a : b;
@@ -126,7 +155,7 @@ ClosureCandidate MapClosures::GetBestClosure(const int query_id,
126155
127156std::vector<ClosureCandidate> MapClosures::GetTopKClosures (
128157 const int query_id, const std::vector<Eigen::Vector3d> &local_map, const int k) {
129- MatchAndAdd (query_id, local_map);
158+ MatchAndAddToDatabase (query_id, local_map);
130159 auto compare_closure_candidates = [](const ClosureCandidate &a, const ClosureCandidate &b) {
131160 return a.number_of_inliers >= b.number_of_inliers ;
132161 };
@@ -156,32 +185,4 @@ std::vector<ClosureCandidate> MapClosures::GetTopKClosures(
156185 std::back_inserter (top_k_closures));
157186 return top_k_closures;
158187}
159-
160- ClosureCandidate MapClosures::ValidateClosure (const int reference_id, const int query_id) const {
161- const Tree::MatchVector &matches = descriptor_matches_.at (reference_id);
162- const size_t num_matches = matches.size ();
163-
164- ClosureCandidate closure;
165- if (num_matches > min_no_of_matches) {
166- std::vector<PointPair> keypoint_pairs (num_matches);
167- std::transform (matches.cbegin (), matches.cend (), keypoint_pairs.begin (),
168- [&](const Tree::Match &match) {
169- auto query_point =
170- Eigen::Vector2d (match.object_query .pt .y , match.object_query .pt .x );
171- auto ref_point = Eigen::Vector2d (match.object_references [0 ].pt .y ,
172- match.object_references [0 ].pt .x );
173- return PointPair (ref_point, query_point);
174- });
175-
176- const auto &[pose2d, number_of_inliers] = RansacAlignment2D (keypoint_pairs);
177- closure.source_id = reference_id;
178- closure.target_id = query_id;
179- closure.pose .block <2 , 2 >(0 , 0 ) = pose2d.linear ();
180- closure.pose .block <2 , 1 >(0 , 3 ) = pose2d.translation () * config_.density_map_resolution ;
181- closure.pose = ground_alignments_.at (query_id).inverse () * closure.pose *
182- ground_alignments_.at (reference_id);
183- closure.number_of_inliers = number_of_inliers;
184- }
185- return closure;
186- }
187188} // namespace map_closures
0 commit comments