大规模创建字典

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

int main( int argc, char** argv )
{
string dataset_dir = argv[1];
ifstream fin ( dataset_dir+"/associate.txt" ); 首先要输入associate.txt文件作为参数,文件里面包含rgb_time,depth_time以及rgb_time对应的图片,depth_time对应的图片所在的文件夹位置
if ( !fin )
{
cout<<“please generate the associate file called associate.txt!”<<endl;
return 1;
}
//
vector< string> rgb_files, depth_files;
vector< double> rgb_times, depth_times;
while ( !fin.eof() )
{
string rgb_time, rgb_file, depth_time, depth_file;
fin>>rgb_time>>rgb_file>>depth_time>>depth_file;//读取文件内容
rgb_times.push_back ( atof ( rgb_time.c_str() ) );
depth_times.push_back ( atof ( depth_time.c_str() ) );
rgb_files.push_back ( dataset_dir+"/"+rgb_file );
depth_files.push_back ( dataset_dir+"/"+depth_file );
//
if ( fin.good() == false )
break;
}
fin.close();
//
cout<<"generating features … "<<endl;
vector< Mat> descriptors;
Ptr< Feature2D > detector = ORB::create();
int index = 1;
for ( string rgb_file:rgb_files )
{
Mat image = imread(rgb_file);
vector< KeyPoint> keypoints;
Mat descriptor;
detector->detectAndCompute( image, Mat(), keypoints, descriptor ); //计算rgb图片的描述子和关键点
descriptors.push_back( descriptor );
cout<<"extracting features from image " << index++ <<endl;
}
cout<<“extract total “<<descriptors.size()*500<<” features.”<<endl;
//
// create vocabulary
cout<<"creating vocabulary, please wait … "<<endl;
DBoW3::Vocabulary vocab;
vocab.create( descriptors );//与之前一样,根据描述子创建字典
cout<<"vocabulary info: "<<vocab<<endl;
vocab.save( “vocab_larger.yml.gz” );
cout<<“done”<<endl;

return 0;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值