zoukankan      html  css  js  c++  java
  • 基于DBoW2生成词袋库Demo

    #include<iostream>
    #include<opencv2/opencv.hpp>
    #include "DBoW2/DBoW2/FORB.h"
    #include "DBoW2/DBoW2/TemplatedVocabulary.h"
    #include<string>
    using namespace std;
    using namespace cv;
    using namespace DBoW2;
    
    typedef DBoW2::TemplatedVocabulary<DBoW2::FORB::TDescriptor, DBoW2::FORB>
    ORBVocabulary;
    
    int main()
    {
        vector<Mat> images;
        int size = 0;
    
        vector<cv::String> filenames;
    
        //for (int i = 0; i < 4; ++i)
        for (int i = 0; i < 3; ++i)
        {
            //cv::String folder = "/home/yangtze/SLAM/dataSet/1280_720/imgs/cam" + to_string(i);
            cv::String folder = "/home/yangtze/SLAM/dataSet/indoor_dynamic/imgs/cam" + to_string(i);
            cv::glob(folder, filenames);
            int nImages = filenames.size();
            size = size + nImages;
            for (int i = 0; i < nImages; ++i)
            {
                images.push_back(imread(filenames[i]));
            }
        }
    
        Ptr<Feature2D>  detector=ORB::create();
    
        vector<Mat> descriptors(size);
    
        vector<vector<cv::Mat > > features;
        features.clear();
        features.reserve(size);
        
    
        for(int i = 0; i < size; ++i)
        {
            cv::Mat image = images[i];
            vector<KeyPoint> keypoints;
            detector->detectAndCompute(image,Mat(),keypoints,descriptors[i]); 
    
        }
        
       // printf("LINE:%d
    ",__LINE__);
        for (int i = 0; i < size; ++i)
        {
            //printf("LINE:%d
    ",__LINE__);
            cv::Mat tmpdescriptor = descriptors[i];
            features.push_back(vector<cv::Mat>());
            for (int j = 0; j < tmpdescriptor.rows; j++)
            {
                //printf("LINE:%d
    ",__LINE__);
                features.back().push_back(tmpdescriptor.row(j));
            }
        
        }
        //printf("LINE:%d
    ",__LINE__);
        const int K = 10;   
        const int L = 5;
        const WeightingType weight = TF_IDF;
        const ScoringType score = L1_NORM;
    
        ORBVocabulary orbVocabulary(K, L, weight, score);
     
        string fileName = "ParkingArea.yaml";
     
        orbVocabulary.create(features);
    
        orbVocabulary.save(fileName);
    
        printf("SAVE TO THE FILE
    ");
    }
  • 相关阅读:
    菜鸟之旅——序章0
    Nginx设置反向代理内网服务器/内部端口
    Laradock ppa加速
    Qt setGraphicsEffect出现崩溃 读取位置 时发生访问冲突
    3.5tensorflow线性回归和线性拟合
    Dockerfile Security Best Practice
    Docker: Exec user process caused "no such file or directory"
    Installing Kubernetes with kops
    Dockerfile 最佳实践
    Configuring HSTS in NGINX
  • 原文地址:https://www.cnblogs.com/yueyangtze/p/13637700.html
Copyright © 2011-2022 走看看