我正在使用OpenCV2.3.1来检测图像中的SIFT关键点。但是我发现在检测结果中,存在重复的点,即有两个关键点具有相同的坐标(以像素为单位),但它们对应的描述符非常不同。以下代码显示了SIFT提取过程。我认为人们应该熟悉使用的“box.png”文件。因此,任何感兴趣的人都可以尝试下面的代码,看看是否与我遇到了同样的问题。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
#include <iostream>
int main( )
{
cv::Ptr<cv::FeatureDetector> detector = cv::FeatureDetector::create( "SIFT" );
cv::Ptr<cv::DescriptorExtractor> extractor = cv::DescriptorExtractor::create("SIFT" );
cv::Mat im = cv::imread("box.png", CV_LOAD_IMAGE_COLOR );
std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors;
detector->detect( im, keypoints);
extractor->compute( im,keypoints,descriptors);
int duplicateNum = 0;
for (int i=0;i<keypoints.size();i++)
{
for (int j=i+1;j<keypoints.size();j++)
{
float dist = abs((keypoints[i].pt.x-keypoints[j].pt.x))+abs((keypoints[i].pt.y-keypoints[j].pt.y));
if (dist == 0)
{
cv::Mat descriptorDiff = descriptors.row(i)-descriptors.row(j);
double diffNorm = cv::norm(descriptorDiff);
std::cout<<"keypoint "<<i<<" equal to keypoint "<<j<<" descriptor distance "<<diffNorm<<std::endl;
duplicateNum++;
}
}
}
std::cout<<"Total keypoint: "<<keypoints.size()<<", duplicateNum: "<<duplicateNum<<std::endl;
return 1;
}