接上一篇:https://blog.csdn.net/xiechaoyi123/article/details/104639462
主要模块:tracking mapping global optimization
模块三:global optimization
主要模块:
包括的数据结构
1)基本数据结构:关键帧序列,当前关键帧以及回环线程指针
//! mutex for access to keyframe queue
mutable std::mutex mtx_keyfrm_queue_;
//! queue for keyframes
std::list<data::keyframe*> keyfrms_queue_;
data::keyframe* cur_keyfrm_ = nullptr;
//! thread for running loop BA
std::unique_ptr<std::thread> thread_for_loop_BA_ = nullptr;
2)基本操作结构:
//(1)回环检测与回环优化
//! loop detector
std::unique_ptr<module::loop_detector> loop_detector_ = nullptr;
//! loop bundle adjuster
std::unique_ptr<module::loop_bundle_adjuster> loop_bundle_adjuster_ = nullptr;
//(2)关键帧网络优化
//! graph optimizer
std::unique_ptr<optimize::graph_optimizer> graph_optimizer_ = nullptr;
3)线程间通信
//! tracking module
tracking_module* tracker_ = nullptr;
//! mapping module
mapping_module* mapper_ = nullptr;
4)重置,等待,终止机制结构
//(1)
//-----------------------------------------
// management for reset process
//! mutex for access to reset procedure
mutable std::mutex mtx_reset_;
//! flag which indicates whether reset is requested or not
bool reset_is_requested_ = false;
//(2)等待机制
//-----------------------------------------
// management for pause process
//! mutex for access to pause procedure
mutable std::mutex mtx_pause_;
//! flag which indicates termination is requested or not
bool pause_is_requested_ = false;
//! flag which indicates whether the main loop is paused or not
bool is_paused_ = false;
//(3)终止机制
//-----------------------------------------
// management for terminate process
//! mutex for access to terminate procedure
mutable std::mutex mtx_terminate_;
//! flag which indicates termination is requested or not
bool terminate_is_requested_ = false;
//! flag which indicates whether the main loop is terminated or not
bool is_terminated_ = true;
主要的操作
1)构造与析构,设置是否需要当前线程-回环检测
//(1)构造与析构
//! Constructor
global_optimization_module(data::map_database* map_db, data::bow_database* bow_db, data::bow_vocabulary* bow_vocab, const bool fix_scale);
//! Destructor
~global_optimization_module();
//(2)设置是否进行当前线程-回环检测
//-----------------------------------------
// interfaces to ON/OFF loop detector
//! Enable the loop detector
void enable_loop_detector();
//! Disable the loop detector
void disable_loop_detector();
//! The loop detector is enabled or not
bool loop_detector_is_enabled() const;
2)线程间通信设置
//! Set the tracking module
void set_tracking_module(tracking_module* tracker);
//! Set the mapping module
void set_mapping_module(mapping_module* mapper);
3)重置,等待,终止机制实现
//(1)重置机制
//-----------------------------------------
// management for reset process
//! Request to reset the global optimization module
//! (NOTE: this function waits for reset)
void request_reset();
//! Check and execute reset
bool reset_is_requested() const;
//! Reset the global optimization module
void reset();
//(2)等待机制
//-----------------------------------------
// management for pause process
//! Request to pause the global optimization module
//! (NOTE: this function does not wait for pause)
void request_pause();
//! Check if the global optimization module is requested to be paused or not
bool pause_is_requested() const;
//! Check if the global optimization module is paused or not
bool is_paused() const;
//! Resume the global optimization module
void resume();
//! Pause the global optimizer
void pause();
//(3)终止机制
//-----------------------------------------
// management for terminate process
//! Request to terminate the global optimization module
//! (NOTE: this function does not wait for terminate)
void request_terminate();
//! Check if the global optimization module is terminated or not
bool is_terminated() const;
//! Check if termination is requested or not
bool terminate_is_requested() const;
//! Raise the flag which indicates the main loop has been already terminated
void terminate();
4)主调接口与主要操作实现:接口,回环检测实现与数据更新
//(1)接口与输入
//-----------------------------------------
// main process
//! Run main loop of the global optimization module
void run();
//! Queue a keyframe to the BoW database
void queue_keyframe(data::keyframe* keyfrm);
//(2)回环检测与数据更新
//! Check if loop BA is running or not
bool loop_BA_is_running() const;
//! Abort the loop BA externally
//! (NOTE: this function does not wait for abort)
void abort_loop_BA();
//! Perform loop closing
void correct_loop();
//2.1 获取回环检测前后的关键帧网络
//! Compute Sim3s (world to covisibility) which are prior to loop correction
module::keyframe_Sim3_pairs_t get_Sim3s_before_loop_correction(const std::vector<data::keyframe*>& neighbors) const;
//! Compute Sim3s (world to covisibility) which are corrected using the estimated Sim3 of the current keyframe
module::keyframe_Sim3_pairs_t get_Sim3s_after_loop_correction(const Mat44_t& cam_pose_wc_before_correction, const g2o::Sim3& g2o_Sim3_cw_after_correction,
const std::vector<data::keyframe*>& neighbors) const;
//2.2 更新三维点landmark和关键帧信息
//! Correct the positions of the landmarks which are seen in covisibilities
void correct_covisibility_landmarks(const module::keyframe_Sim3_pairs_t& Sim3s_nw_before_correction,
const module::keyframe_Sim3_pairs_t& Sim3s_nw_after_correction) const;
//! Correct the camera poses of the covisibilities
void correct_covisibility_keyframes(const module::keyframe_Sim3_pairs_t& Sim3s_nw_after_correction) const;
//! Detect and replace duplicated landmarks
void replace_duplicated_landmarks(const std::vector<data::landmark*>& curr_match_lms_observed_in_cand,
const module::keyframe_Sim3_pairs_t& Sim3s_nw_after_correction) const;
//2.3 更新关键帧网络结构信息
//! Extract the new connections which will be created AFTER loop correction
std::map<data::keyframe*, std::set<data::keyframe*>> extract_new_connections(const std::vector<data::keyframe*>& covisibilities) const;
来源:CSDN
作者:xiechaoyi123
链接:https://blog.csdn.net/xiechaoyi123/article/details/104640021