我不确定我是否完全理解你的问题。
我的理解是:
- 您将使用关键点比较图像
- 您想比较匹配关键点的大小
首先你想要至少 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
就是这样!希望这会有所帮助