2014-11-25 73 views
0

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

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

+0

为什么你认为它很重要,如果他们有不同的大小?通常,您会为关键点提取描述符,并匹配这些关键点,而不是关键点。 – berak 2014-11-25 11:52:50

+0

,因为我必须删除与第一张图像的关键点相比变小或相同的关键点。我也需要SURF特征的方向。如何通过关键点提取的描述符来比较关键点的大小? – AKmin 2014-11-25 12:25:26

+0

对不起,我不明白,你在说什么。 – berak 2014-11-25 13:32:59

回答

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); 

使用例如暴力破解与L2范数然后相匹配的关键点的描述符:

BFMatcher matcher(NORM_L2); 
vector<DMatch> matches; 
matcher.match(descriptors1, descriptors2, 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

就是这样!希望这可以帮助

+0

谢谢,这是真的。 – AKmin 2014-12-05 10:49:03