SLAM~CH11

意义:1. 保证估计的轨迹和地图在长时间下的正确性

           2. 可以利用回环检测进行重定位

基于外观的检测方法

特点:基于外观的方法。与前后端的估计都无关,仅考虑两幅图像的相似性。

核心问题:如何计算图像的相似性

引入:准确率和召回率

 Precesion=\frac{TP}{TP+FP}                Recall=\frac{TP}{TP+FN}

准确率:算法提取的所有回环中确实是真实回环的概率

召回率:所有真实回环被正确检测出来的概率

这两个率通常是一对矛盾:

 词袋模型

步骤

1. 构建字典

2. 确定图像里出现了那些word。用单词出现的情况转化成向量的描述。(假如“人”“车”“狗”是记录在字典里的.A=(1,1,0)可以表述图像里有人,有狗

3. 比较上一步描述的相似程度。求差有不同的方法:如

    

 构建字典

 K-means法

 基于K-means的k叉树法

 该字典一共可以容纳k^d个单词。在查询某个特征给定的单词时,只需将它与每个中间节点的聚类比较(一共k次)。

       代码

1. 查找特征点

2. DBow3::Vocabulary vocab;

    vocab.create(descriptors);

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;
}

相似度计算

1. 已有建立好的字典进行权重

 我们在建立字典的时候计算IDF:IDF_i=log\frac{n}{n_i}。  n是所有特征的数量,子叶点的特征点数量是n_i

 因此,该图像的权重为:

                                                        ​​​​​​​     \eta _i=TF_i*IDF_i

 2. 两个图像进行对比

其中一种范数:s(\nu _A-\nu _B)=2\sum_{i=1}^N|\nu _{Ai}|+|\nu _{Bi}|-|\nu _{Ai}-\nu _{Bi}|

         代码

1. 读取字典

DBoW3::Vocabulary vocab("./vocabulary.yml.gz");

2. 读取图像

    vector<Mat> images;
    for (int i = 0; i < 10; i++) {
        string path = "./data/" + to_string(i + 1) + ".png";
        images.push_back(imread(path));
    }

3. 检测图像的特征

    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);
    }

4. 对比图像

方法一:图像与图像直接对比

其中,把特征转化为BoW:vocab.transform(descriptors[i],v1);

                          得出分数:double score = vocab.score(v1, v2);

   cout << "comparing images with images " << endl;
    for (int i = 0; i < images.size(); i++) {
        DBoW3::BowVector v1;
        vocab.transform(descriptors[i], v1);
        for (int j = i; j < images.size(); j++) {
            DBoW3::BowVector v2;
            vocab.transform(descriptors[j], v2);
            double score = vocab.score(v1, v2);
            cout << "image " << i << " vs image " << j << " : " << score << endl;
        }
        cout << endl;
    }

方法二:图像与数据库里的对比(数据库在这个例子其实也是所有图像转化来的) 

    cout << "comparing images with database " << endl;
    DBoW3::Database db(vocab, false, 0);
    for (int i = 0; i < descriptors.size(); i++)
        db.add(descriptors[i]);
    cout << "database info: " << db << endl;
    for (int i = 0; i < descriptors.size(); i++) {
        DBoW3::QueryResults ret;
        db.query(descriptors[i], ret, 4);      // 在数据库里找4个最相似的图像
        cout << "searching for image " << i << " returns " << ret << endl << endl;
    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值