【问题标题】:how to compare size of kepoints matching in opencv如何比较opencv中匹配的kepoints的大小
【发布时间】:2015-01-23 09:41:15
【问题描述】:

我将在 opencv 中将图像与 SURF 检测器进行比较。对于这项工作,我需要必须比较它们的关键点的大小和方向。例如,我必须提取第二张图像的关键点匹配大于第一张图像的关键点匹配。 (关键点 1.size > 关键点 2.size)。

问题: 如何提取opencv中匹配的关键点的大小?

【问题讨论】:

  • 如果它们的尺寸不同,为什么你认为这很重要?通常,您会提取关键点的描述符,然后匹配这些描述符,而不是关键点。
  • 因为我必须删除变小或与第一张图像的关键点相同的关键点。我还需要调整 SURF 特征的方向。如何通过关键点提取的描述符比较关键点的大小?
  • 对不起,我不明白你在说什么。
  • @AKmin 你说“第一张图像的关键点匹配”和“第二张图像的关键点匹配”是什么意思?

标签: c++ opencv matching surf


【解决方案1】:

我不确定我是否完全理解你的问题。

我的理解是:

  1. 您将使用关键点比较图像
  2. 您想比较匹配关键点的大小

首先你想要至少 2 张图片:

Mat image1; //imread stuff here
Mat image2; //imread stuff here

然后使用 SURF 检测两个图像中的关键点:

vector<KeyPoint> keypoints1, keypoints2; //store the keypoints
Ptr<FeatureDetector> detector = new SURF();
detector->detect(image1, keypoints1); //detect keypoints in 'image1' and store them in 'keypoints1'
detector->detect(image2, keypoints2); //detect keypoints in 'image2' and store them in 'keypoints2'

然后计算检测到的关键点的描述符:

Mat descriptors1, descriptors2;
Ptr<DescriptorExtractor> extractor = new SURF();
extractor->compute(image1, keypoints1, descriptors1);
extractor->compute(image2, keypoints2, descriptors2);

然后使用例如 BruteForce 和 L2 norm 匹配关键点的描述符:

BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);

在这些步骤之后,匹配的关键点被存储在向量“matches”中

您可以通过以下方式获取匹配关键点的索引:

//being idx any number between '0' and 'matches.size()'   
int keypoint1idx = matches[idx].query; //keypoint of the first image 'image1'
int keypoint2idx = matches[idx].train; //keypoint of the second image 'image2'

阅读本文以获取更多信息: http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html

最后,要知道匹配关键点的大小,您可以执行以下操作:

int size1 = keypoints1[ keypoint1idx ].size; //size of keypoint in the image1
int size2 = keypoints2[ keypoint2idx ].size; //size of keypoint in the image2

更多信息:http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html

就是这样!希望这会有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 2014-11-07
    • 2015-03-07
    • 2015-05-26
    • 2020-02-28
    相关资源
    最近更新 更多