#include "DBoW3/DBoW3.h" //使用了BOW这个库
#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;

int main( int argc, char** argv )
{
    // read the image
    cout<<"reading images... "<<endl;
    vector<Mat> images;
    for ( int i=0; i<10; i++ )//这里选取了10张图片
    {
        string path = "/home/hansry/Slam_Book/src/Feature_traning/data/"+to_string(i+1)+".png";
        images.push_back( imread(path) );
    }
    // detect ORB features
    cout<<"detecting ORB features ... "<<endl;
    Ptr< Feature2D > detector = ORB::create("FAST");//由于这里用的是opencv2,所以略有不同
    vector<Mat> descriptors; 
    for ( Mat& image:images )
    {
        vector<KeyPoint> keypoints;
        Mat descriptor;
        ORB orb;
        orb( 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;
}

cmake_minimum_required(VERSION 2.8.3)
project(Feature_traning)

set(CMAKE_CXX_FLAGS "-std=c++11 -O3")
find_package(OpenCV  REQUIRED ) //这里有点不同,把原版的cmakelist代码里的opencv 3.1改为 2.4(我用的2.4,高博用的3.1.。。。)
set( DBoW3_INCLUDE_DIRS "/usr/local/include" )
set( DBoW3_LIBS "/usr/local/lib/libDBoW3.so" ) //这里,还有个问题,就是在编译DBoW库的时候,cmake ..后需要“sudo make install”   切记!!!
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES test
#  CATKIN_DEPENDS opencv roscpp
#  DEPENDS system_lib
)

include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)
add_executable(Feature_traning src/Feature_traning.cpp)

target_link_libraries(Feature_traning
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
   ${DBoW3_LIBS}
)

多说一句,建议换用原版cmakelist  这个感觉是网友自己写的额#、#

其余的就没啥了。无错误,流下感动热泪!

附上我遇到的坑

1.

肺炎期间的科研实验之--0301 词袋模型DBoW3跳坑!!!!

2.

肺炎期间的科研实验之--0301 词袋模型DBoW3跳坑!!!!

3.

肺炎期间的科研实验之--0301 词袋模型DBoW3跳坑!!!!

然后,新世界 ...

肺炎期间的科研实验之--0301 词袋模型DBoW3跳坑!!!!

就是接么豪横  接么局气!

相关文章: