由于前端里程计只考虑相邻两帧之间的运动,这样产生的误差会传递到下一时刻。使用后端优化利用尽量多的数据消除了部分误差,但为了使地图更加精确,需要回环检测,保证全局一致性。
准确率:在所有判断是回环中,实际与判断一致的比率(准确率是指判断是否准确)
召回率:在所有事实是回环中,实际与判断一致的比率(召回率是指在事实中选中了的概率)
词袋模型(单词,字典)
字典的生成使用了K-means聚类算法
步骤:
1. 随机选择k个中心点
2. 计算每个样本到最小重心点的距离,最小的为它的归类
3. 重新计算每个类的中心点
为了方便查找,使用k叉树进行聚类。
#include "DBoW3/DBoW3.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <iostream>
#include <vector>
#include <string>
using namespace cv;
using namespace std;
/***************************************************
* 本节演示了如何根据data/目录下的十张图训练字典
* ************************************************/
int main( int argc, char** argv ) {
// read the image
cout<<"reading images... "<<endl;
vector<Mat> images;
for ( int i=0; i<10; i++ )
{
string path = "./data/"+to_string(i+1)+".png";
images.push_back( imread(path) );
}
// detect ORB features
cout<<"detecting ORB features ... "<<endl;
Ptr< Feature2D > detector = ORB::create();
vector<Mat> descriptors;
for ( Mat& image:images )
{
vector<KeyPoint> keypoints;
Mat descriptor;
detector->detectAndCompute( image, Mat(), keypoints, descriptor );
descriptors.push_back( descriptor );
}
// create vocabulary
cout<<"creating vocabulary ... "<<endl;
DBoW3::Vocabulary vocab;
vocab.create( descriptors );
cout<<"vocabulary info: "<<vocab<<endl;
vocab.save( "vocabulary.yml.gz" );
cout<<"done"<<endl;
return 0;
}
相似度计算
单词在一幅图像中经常出现,在字典中较少出现,说明区分度很高。
TF-IDF频率-逆文档频率
增加了字典规模后,无关图像的相似性减小