MCPcopy Create free account
hub / github.com/PeterFWS/Structure-PLP-SLAM / correct_loop

Method correct_loop

src/PLPSLAM/global_optimization_module.cc:191–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189 }
190
191 void global_optimization_module::correct_loop()
192 {
193 auto final_candidate_keyfrm = loop_detector_->get_selected_candidate_keyframe();
194
195 spdlog::info("detect loop: keyframe {} - keyframe {}", final_candidate_keyfrm->id_, cur_keyfrm_->id_);
196 loop_bundle_adjuster_->count_loop_BA_execution();
197
198 // [1] pre-processing
199
200 // stop the mapping module and the previous loop bundle adjuster
201 // pause the mapping module
202 mapper_->request_pause();
203
204 // abort the previous loop bundle adjuster
205 if (thread_for_loop_BA_ || loop_bundle_adjuster_->is_running())
206 {
207 abort_loop_BA();
208 }
209
210 // wait till the mapping module pauses
211 while (!mapper_->is_paused())
212 {
213 std::this_thread::sleep_for(std::chrono::milliseconds(2));
214 }
215
216 // update the graph, because we got new matched landmarks by loop detection -> loop_detector::curr_match_lms_observed_in_cand_
217 cur_keyfrm_->graph_node_->update_connections();
218
219 // [2] compute the Sim3 of the covisibilities of the current keyframe whose Sim3 is already estimated by the loop detector
220 // then, the covisibilities are moved to the corrected positions
221 // finally, landmarks observed in them are also moved to the correct position using the camera poses before and after camera pose correction
222
223 // acquire the covisibilities of the current keyframe
224 std::vector<data::keyframe *> curr_neighbors = cur_keyfrm_->graph_node_->get_covisibilities();
225 curr_neighbors.push_back(cur_keyfrm_);
226
227 // Sim3 camera poses BEFORE loop correction
228 module::keyframe_Sim3_pairs_t Sim3s_nw_before_correction;
229 // Sim3 camera poses AFTER loop correction
230 module::keyframe_Sim3_pairs_t Sim3s_nw_after_correction;
231
232 const auto g2o_Sim3_cw_after_correction = loop_detector_->get_Sim3_world_to_current();
233 {
234 std::lock_guard<std::mutex> lock(data::map_database::mtx_database_);
235
236 // camera pose of the current keyframe BEFORE loop correction
237 const Mat44_t cam_pose_wc_before_correction = cur_keyfrm_->get_cam_pose_inv();
238
239 // compute Sim3s BEFORE loop correction
240 Sim3s_nw_before_correction = get_Sim3s_before_loop_correction(curr_neighbors);
241 // compute Sim3s AFTER loop correction
242 Sim3s_nw_after_correction = get_Sim3s_after_loop_correction(cam_pose_wc_before_correction, g2o_Sim3_cw_after_correction, curr_neighbors);
243
244 // correct covisibility landmark positions
245 correct_covisibility_landmarks(Sim3s_nw_before_correction, Sim3s_nw_after_correction);
246 // correct covisibility keyframe camera poses
247 correct_covisibility_keyframes(Sim3s_nw_after_correction);
248

Callers

nothing calls this directly

Calls 15

infoFunction · 0.85
is_runningMethod · 0.80
update_connectionsMethod · 0.80
get_covisibilitiesMethod · 0.80
get_cam_pose_invMethod · 0.80
add_loop_edgeMethod · 0.80
request_pauseMethod · 0.45

Tested by

no test coverage detected