美文网首页SLAM、OpenCV、Linux、ROS等
OpenCV 2.4.13中把Bow保存为词典

OpenCV 2.4.13中把Bow保存为词典

作者: 一恪slam | 来源:发表于2018-12-12 00:53 被阅读0次

环境依赖

本示例依赖于OpenCV 2.4.13

项目应用

应用于SLAM中回环检测

具体代码

// Created by yike on 18-12-11.

#include <iostream>
#include <fstream>

#include "opencv2/opencv_modules.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/nonfree/nonfree.hpp"

using namespace cv;
using namespace std;

const int N=2;

int main(){

    const string imgName1 = "/home/gzz/CLionProjects/fabmap/fabmap/5000.jpg";
    const string imgName2 = "/home/gzz/CLionProjects/fabmap/fabmap/5005.jpg";

    Vector<Mat> imgs;
    imgs.push_back(imread(imgName1));
    imgs.push_back(imread(imgName2));

    //Creating detector, descriptor extractor and descriptor matcher
    cout << "Creating detector, descriptor extractor\n";
    Ptr<FeatureDetector> detector =
            new DynamicAdaptedFeatureDetector(
                    AdjusterAdapter::create("STAR"), 500, 1500, 5);
    Ptr<DescriptorExtractor> extractor =
            new SurfDescriptorExtractor(1000, 4, 2, false, true);

    //begin the bow training
    BOWKMeansTrainer bowTraining(1000);
    vector<KeyPoint> kps;
    Mat descriptors;
    for (int i = 0; i<N;i++){
        detector->detect(imgs[i],kps);
        extractor->compute(imgs[i],kps,descriptors);
        bowTraining.add(descriptors);
    }
    //generate the dictionary
    Mat dictionary = bowTraining.cluster();

    //save the dictionary to file
    FileStorage fs;
    fs.open("./fabmap/voc.yml",FileStorage::WRITE);
    fs <<"Vocabulary" <<dictionary;
    fs.release();

    cout<<"done!"<<endl;

    return 0;
}

相关文章

  • OpenCV 2.4.13中把Bow保存为词典

    环境依赖 本示例依赖于OpenCV 2.4.13 项目应用 应用于SLAM中回环检测 具体代码

  • 视觉词典在SLAM中应用

    前言 视觉词典技术是采用视觉Bag-of-word模型的技术。BOW模型最先是信息检索领域常用的文档表示方法,它假...

  • OpenCV|图片与视频的相互转换(C++&Python

    前言 在学习opencv的过程中,终会遇到需要把视频转换成图片处理,或者把处理后的图片保存为视频格式的时候。这篇文...

  • opencv 读取设备数据并保存为视频

    opencv 读取设备数据并保存为视频 包含头文件 转换格式并保存 注意: 必须加cv::waitKey(1);即...

  • 缘分

    我不喜欢喧闹,所以我在巴士上听歌: “BOW BOW BOW,让我看到你双手, 对抗地心引力一起反转地球, BOW...

  • 流利阅读DAY60

    Day 60 1.bow /boʊ/ n. 弓;鞠躬 (bow v.) e.g. to bow to sb (v....

  • Python+OpenCV调用摄像头接口打造家庭安防系统 !

    问题描述:使用Python+opencv调用笔记本摄像头接口,定期捕捉图像或录制视频并保存为图像文件或视频文件。可...

  • BOW模型

    1.BOW: Bag of words 词袋模型。2.Bg: 最初被用在文本分类中,将文档表示成特征矢量。它...

  • Bow Tie

    『Bow ties are cool, I wear it and I don't care, that's wh...

  • Take A Bow

    Take A Bow Rihanna Ohh, how about a round of applause, 喔,...

网友评论

    本文标题:OpenCV 2.4.13中把Bow保存为词典

    本文链接:https://www.haomeiwen.com/subject/runyhqtx.html