我基本上是从相似的图像中提取许多带有 SURF 的关键点并将它们添加到BFMatcher(NORM_L2)
在运行时我可能会在我的匹配器中添加新的关键点matcher->add(myNewDescriptors);
现在,当我添加了一个只有 1 个关键点/描述符的图像并且我使用 knnMatch 时,它不会返回任何匹配项:
matcher->knnMatch(queryDesc,matches,2);
过了一会儿,我得到了一个最近邻居为 0 的向量:
for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;
//> PRINTS: "matches size: 0"
仅当我插入只有 1 个关键点/描述符的图像时才会发生这种情况。在 knnMatch 工作正常之前。
我试图检查是否matcher.getTrainDescriptors();
包含我的描述符并有效地包含所有内容。要检查这一点,如果我这样做:
cout << matcher->getTrainDescriptors().at(0).size(); // (Get the size of the descriptors Mat associated to the first training image)
我得到:[128 x 32]。这意味着描述符在那里,但 knnMatches 返回一个空向量
另请注意,如果我用简单的 .match 更改 .knnMatch ,则匹配器会正常返回所有 DMatch!代码仅因 knnMatch 而失败
- OpenCV:2.4.5