做slam怎么能少得了闭环。
闭环检测的代码在文件include/hdl_graph_slam/loop_detector.hpp中,整个流程分布的很清晰,我们直接进入看代码的环节了
1. 整体流程
在调用闭环检测功能时,实际是调用的函数detect,所以我们直接看这个函数,就可以看出它的流程
std::vector<:ptr> detect(const std::vector<:ptr>& keyframes, const std::deque<:ptr>& new_keyframes, hdl_graph_slam::GraphSLAM& graph_slam) {
std::vector<:ptr> detected_loops;
for(const auto& new_keyframe : new_keyframes) {
auto candidates = find_candidates(keyframes, new_keyframe);
auto loop = matching(candidates, new_keyframe, graph_slam);
if(loop) {
detected_loops.push_back(loop);
}
}
return detected_loops;
}
它的输入是:
1)keyframes:已有的关键帧
2)new_keyframes:新增的关键帧
3)graph_slam:这个参数没有被用到,估计作者可能是原计划要用,但后来没用到,也忘了删了
它的输出是:
1)std::vector<:ptr>:所有检测成功的匹配关系
具体来讲,包括它是由哪两帧匹配的,匹配计算得到的相对位姿是多少。
这个看Loop这个结构提的定义就明白了
struct Loop {
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
using Ptr = std::shared_ptr;
Loop(const KeyFrame::Ptr& key1, const KeyFrame::Ptr& key2, const Eigen::Matrix4f& relpose)
: key1(key1),
key2(key2),
relativ