【視覺slam十四講】ch12:詞袋模型
阿新 • • 發佈:2019-01-02
看高博的十四講,跑了建立字典的例子,但是顯示單詞數是0:Number of words=0
vocabulary info: Vocabulary: k = 10, L = 5, Weighting = tf-idf, Scoring = L1-norm, Number of words = 0
剛開始懷疑DBoW3裝的不對,但是重灌之後還是不行,沒辦法我就從頭調程式碼,在讀取圖片的時候發現圖片為空。於是懷疑圖片路徑不對,填寫了完整的路徑,發現可以了。
#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 = "/home/user/ch12/data/"+to_string(i+1)+".png";//需要完整路徑 images.push_back( imread(path) ); if(!images[i].empty())//如果讀取的圖片為空就輸出提示,很坑啊,希望大家注意 { imshow("讀取影象", images[i]); waitKey(30); } else { cout<<"image is empty"<<endl; } } // 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; }
耐心一些,多去找方法想問題。
每天一點進步,堅持下去。