C++ OpenCV-两个完全不同的图像使用BFMatcher进行更多匹配

C++ OpenCV-两个完全不同的图像使用BFMatcher进行更多匹配,c++,opencv,image-processing,computer-vision,surf,C++,Opencv,Image Processing,Computer Vision,Surf,我有一些杯子的照片 还有一张猫的照片 我想使用surf在OpenCV中比较这两张图片,并使用BFMatcher进行匹配 代码如下: //read the image cv::Mat image1= cv::imread("C:\\Users\\The\\Desktop\\cub.jpg"); cv::Mat image2= cv::imread("C:\\Users\\The\\Desktop\\cat.jpg"); //detect the key points using surf cv::

我有一些杯子的照片

还有一张猫的照片

我想使用surf在OpenCV中比较这两张图片,并使用BFMatcher进行匹配

代码如下:

//read the image
cv::Mat image1= cv::imread("C:\\Users\\The\\Desktop\\cub.jpg");
cv::Mat image2= cv::imread("C:\\Users\\The\\Desktop\\cat.jpg");
//detect the key points using surf
cv::SurfFeatureDetector surf(300,4,2,true,false);
   //image 1 key points
vector<cv::KeyPoint> image1Keypoints;
//detect the key points in image 1 using surf
surf.detect(image1,image1Keypoints);
//draw the keypoints of image1
cv::drawKeypoints(image1,image1Keypoints,image1,                                      
  cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);
cv::namedWindow("Original image 1 with keypoints");
cv::imshow("Original image 1 with keypoints",image1);
// image 2 key points
std::vector<cv::KeyPoint> image2keypoints;
//detect the key points in image 1 using surf
 surf.detect(image2,image2keypoints);
 //draw the key points
 cv::drawKeypoints(image2,keypoints1,image2,                                   
      cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);                      
 //the extracted image display
cv::namedWindow("image 2 with keypoints");
cv::imshow("image 2 with keypoints",image2);
//读取图像
cv::Mat image1=cv::imread(“C:\\Users\\The\\Desktop\\cub.jpg”);
cv::Mat image2=cv::imread(“C:\\Users\\The\\Desktop\\cat.jpg”);
//使用surf检测关键点
cv::SurfFeatureDetector surf(300,4,2,真,假);
//图1关键点
矢量图像1个关键点;
//使用surf检测图像1中的关键点
表面检测(图像1、图像1关键点);
//绘制图1的关键点
cv::drawKeypoints(图像1、图像1关键点、图像1、,
cv::Scalar(255255255),cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);
cv::namedWindow(“带关键点的原始图像1”);
cv::imshow(“带关键点的原始图像1”,图像1);
//图2关键点
std::矢量图像2个关键点;
//使用surf检测图像1中的关键点
表面检测(图像2、图像2关键点);
//画重点
cv::drawKeypoints(图2、keypoints1、图2、,
cv::Scalar(255255255),cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);
//提取的图像显示
cv::namedWindow(“带关键点的图像2”);
cv::imshow(“带关键点的图像2”,图像2);
从上面的代码中可以看到cups图像功能

和cat图像功能:

cv::SiftDescriptorExtractor-sift;
cv::Mat Image1描述器;
cv::Mat Image2Descriptor;
筛选计算(图1,
image1Keypoints,
图像1描述器);
筛选计算(图2,
关键点1,
Image2Descriptor);
cv::BFMatcher matcher(cv::NORM_L2,true);
向量匹配;
matcher.match(Image2Descriptor、image1Descriptor、matches);
你应该检查一下这个

通常,BruteForce将返回两个匹配之间的距离。两个要素之间的距离越小,它们就越相似。通过在这些距离上应用阈值,将有助于消除假阳性匹配


但是,特征匹配本身并不能保证两个图像中的对象是相同的。要进行这种验证,您需要在实现上做得更进一步,(例如)用单应性几何验证正匹配。

当我滚动时,我看到一个故事-DYou正在比较小的图像块(32x32左右),即描述符。。。匹配描述符并不意味着比较图像。匹配后,您必须执行一些其他步骤。@POW我的问题是针对两个不同的图像,如何能够进行如此多的匹配,以及如何减少匹配数?@Miki您能否详细说明“匹配后必须使用其他步骤”的意思?我是opencv的初学者。例如,估计匹配关键点上的转换,并检查异常值的数量。更少的异常值意味着更相似的图像。或者在诸如BoW、SVM之类的分类器中使用描述符。
cv::SiftDescriptorExtractor sift;
cv::Mat image1Descriptor;
cv::Mat image2Desccriptor;
sift.compute(image1,
             image1Keypoints,
             image1Descriptor);
sift.compute(image2,
             keypoints1,
             image2Desccriptor);
 cv::BFMatcher matcher(cv::NORM_L2,true);
std::vector<cv::DMatch> matches;
matcher.match(image2Desccriptor,image1Descriptor,matches);
cout<<"match=";
//the number of matched features between the two images
cout<<matches.size()<<endl;
cv::Mat imageMatches;   
cv::drawMatches(image2,keypoints1,image1,image1Keypoints,                
   matches,imageMatches,cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);              
cv::namedWindow("matches");
cv::imshow("matches",imageMatches);
cv::waitKey(0);