我已经设法让 VlFeat 的 SIFT 实现工作,我想尝试匹配两组图像描述符。
SIFT 的特征向量是 128 个元素的浮点数组,我将描述符列表存储在std::vector
s 中,如下面的片段所示:
std::vector<std::vector<float> > ldescriptors = leftImage->descriptors;
std::vector<std::vector<float> > rdescriptors = rightImage->descriptors;
/* KDTree, L1 comparison metric, dimension 128, 1 tree, L1 metric */
VlKDForest* forest = vl_kdforest_new(VL_TYPE_FLOAT, 128, 1, VlDistanceL1);
/* Build the tree from the left descriptors */
vl_kdforest_build(forest, ldescriptors.size(), ldescriptors.data());
/* Searcher object */
VlKDForestSearcher* searcher = vl_kdforest_new_searcher(forest);
VlKDForestNeighbor neighbours[2];
/* Query the first ten points for now */
for(int i=0; i < 10; i++){
int nvisited = vl_kdforestsearcher_query(searcher, &neighbours, 2, rdescriptors[i].data());
cout << nvisited << neighbours[0].distance << neighbours[1].distance;
}
据我所知,这应该可行,但我所得到的只是距离nan
。描述符数组结帐的长度,因此似乎确实有数据进入树。我已经绘制了关键点,它们看起来也很合理,因此数据相当合理。
我错过了什么?
这里的文档很少(API 链接):http ://www.vlfeat.org/api/kdtree.html