从OpenCV SIFT匹配中获取关键点的坐标

3

我希望能够从OpenCV SIFT匹配中获取关键点的坐标,但我不知道匹配数据结构的注释。我一直在尝试着这样做:

vector<DMatch> matches;
matcher.match(descriptors1,descriptors2,matches);
for(vector<DMatch>::size_type i=0; i<matches.size(); i++)
{
    cout<< key_points1[ matches[i].trainIdx].pt <<"与之匹配特征点坐标"<< key_points2[ matches[i].imgIdx].pt<<endl; 
}

但是它不起作用。有人能帮我吗?

我已经尝试了你的方法,它完全有效。你是如何存储你的关键点的?如果你还卡住了,更多的代码会很有帮助。 - user3510227
请您详细说明 "不起作用" 是指什么?您收到了什么样的错误信息?或者描述一下实际输出和期望输出之间的差异。 - nils
1个回答

3

DescriptorMatcher 类的 match 函数签名如下:

void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
            vector<DMatch>& matches, const Mat& mask=Mat() ) const;

我假设key_points1对应于descriptors1key_points2对应于descriptors2
首先需要检查的是您将descriptors1作为queryDescriptors传递,但随后使用trainIdx作为索引。您可能需要在那里使用queryIdx
因此,对于key_points2,您需要使用trainIdx
vector<DMatch> matches;
matcher.match(descriptors1,descriptors2,matches);
for(vector<DMatch>::size_type i=0; i<matches.size(); i++)
{
  cout<< key_points1[ matches[i].queryIdx].pt // Query is first.
      <<"与之匹配特征点坐标"
      << key_points2[ matches[i].trainIdx].pt // Training is second.
      <<endl; 
}

希望能帮到您!

谢谢。我明白了。我使用了你所说的相同解决方案。 - user4705465

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接