本文整理汇总了C++中Vocabulary::search方法的典型用法代码示例。如果您正苦于以下问题:C++ Vocabulary::search方法的具体用法?C++ Vocabulary::search怎么用?C++ Vocabulary::search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vocabulary
的用法示例。
在下文中一共展示了Vocabulary::search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
{
labels.push_back(i);
}
}
Mat all_descriptors;
for(int i = 0; i<descriptorsVec.size(); i++)
{
all_descriptors.push_back(descriptorsVec[i]);
}
assert(labels.size() == all_descriptors.rows);
cout<<"all_descriptors.rows "<<all_descriptors.rows<<endl;
cout<<"hahha1 "<<endl;
Vocabulary vocab;
vocab.indexedDescriptors_ = all_descriptors;
vector<KeyPoint> newKeypoints;
Mat newDescriptors;
///add new image to the randomized kd tree
{
string newImageName="/home/lili/workspace/SLAM/vocabTree/Lip6IndoorDataSet/Images/lip6kennedy_bigdoubleloop_000350.ppm";
Mat newImg=imread(newImageName, CV_LOAD_IMAGE_GRAYSCALE);
detector.detect(newImg, newKeypoints);
extractor.compute(newImg, newKeypoints, newDescriptors);
cout<<"newDescriptors.rows: "<<newDescriptors.rows<<endl;
}
vocab.notIndexedDescriptors_ = newDescriptors;
///clustering
int clustersNum;
Mat clusters(15000,64,CV_32F);
//Mat float_all_descriptors;
clustersNum=vocab.clustering(all_descriptors, clusters);
cout<<"clustersNum "<<clustersNum<<endl;
///flann build tree
clock_t begin1 = clock();
vocab.update();
clock_t end1 = clock();
double buildTree_time = double(end1 - begin1) / CLOCKS_PER_SEC;
cout.precision(5);
cout<<"buildTree time "<<buildTree_time<<endl;
cout<<"hahha2 "<<endl;
vector<KeyPoint> queryKeypoints;
Mat queryDescriptors;
///QueryImage
{
string queryImageName="/home/lili/workspace/SLAM/vocabTree/Lip6IndoorDataSet/Images/lip6kennedy_bigdoubleloop_000381.ppm";
Mat queryImg=imread(queryImageName, CV_LOAD_IMAGE_GRAYSCALE);
detector.detect(queryImg, queryKeypoints);
extractor.compute(queryImg, queryKeypoints, queryDescriptors);
cout<<"queryDescriptors.rows: "<<queryDescriptors.rows<<endl;
}
Mat indices;
Mat dists;
int k=2;
clock_t begin2 = clock();
vocab.search(queryDescriptors, indices, dists, k);
clock_t end2 = clock();
double query_time = double(end2 - begin2) / CLOCKS_PER_SEC;
cout.precision(5);
cout<<"query time "<<query_time<<endl;
std::vector<int> indicesVec(indices.rows*indices.cols);
if (indices.isContinuous())
{
indicesVec.assign((int*)indices.datastart, (int*)indices.dataend);
}
cout<<"indicesVec.size() "<<indicesVec.size()<<endl;
/// Process Nearest Neighbor Distance Ratio
float nndRatio = 0.8;
for(int i=0; i<indicesVec.size(); i++)
{
if(dists.at<float>(i,0)<nndRatio*dists.at<float>(i,1))
{
cout<<"indicesVec["<<i<<"] "<<indicesVec[i]<<" image labels "<<labels[indicesVec[i]]<<endl;
}
}
return 0;
}