我将在opencv中将图像与冲浪探测器进行比较。对于这项工作,我需要大小和方向的关键点,必须进行比较。例如,我必须提取第二个图像的关键点匹配大于第一个图像的关键点匹配。(keypoint 1. 1.size > keypoint 2.1.size)
问题:如何提取opencv?中的关键点匹配大小
发布于 2014-12-04 16:26:15
我不确定我是否完全理解你的问题。
我所理解的是:
首先,你需要至少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规范匹配关键点的描述符:
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'
有关更多信息,请阅读以下内容:matchers.html
最后,要知道匹配的关键点的大小,可以执行以下操作:
int size1 = keypoints1[ keypoint1idx ].size; //size of keypoint in the image1
int size2 = keypoints2[ keypoint2idx ].size; //size of keypoint in the image2
更多信息:detectors.html
就这样!希望这能有所帮助
https://stackoverflow.com/questions/27125817
复制