【笔记】Opencv Surf算子特征提取与最优匹配

CV_WRAP SURF(double hessianThreshold,
                  int nOctaves=4, int nOctaveLayers=2,
                  bool extended=true, bool upright=false);

void drawKeypoints( const Mat& image, const vector<KeyPoint>& keypoints, CV_OUT Mat& outImage,
                               const Scalar& color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT );

 

drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
                             const Mat& img2, const vector<KeyPoint>& keypoints2,
                             const vector<DMatch>& matches1to2, Mat& outImg,
                             const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
                             const vector<char>& matchesMask=vector<char>(), int flags=DrawMatchesFlags::DEFAULT );

 

#include "highgui/highgui.hpp"  
#include "opencv2/nonfree/nonfree.hpp"  
#include "opencv2/legacy/legacy.hpp" 
#include <iostream>
 
using namespace cv;
using namespace std;
 
int main(int argc,char *argv[])  
{  
	Mat image01=imread(argv[1]);  
	Mat image02=imread(argv[2]);  
	Mat image1,image2;  
	image1=image01.clone();
	image2=image02.clone();
 
	//提取特征点  
	SurfFeatureDetector surfDetector(4000);  //hessianThreshold,海塞矩阵阈值,并不是限定特征点的个数 
	vector<KeyPoint> keyPoint1,keyPoint2;  
	surfDetector.detect(image1,keyPoint1);  
	surfDetector.detect(image2,keyPoint2);  
 
	//绘制特征点  
	drawKeypoints(image1,keyPoint1,image1,Scalar::all(-1),DrawMatchesFlags::DEFAULT);    
	drawKeypoints(image2,keyPoint2,image2,Scalar::all(-1),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);     
	imshow("KeyPoints of image1",image1);  
	imshow("KeyPoints of image2",image2);  
 
	//特征点描述,为下边的特征点匹配做准备  
	SurfDescriptorExtractor SurfDescriptor;  
	Mat imageDesc1,imageDesc2;  
	SurfDescriptor.compute(image1,keyPoint1,imageDesc1);  
	SurfDescriptor.compute(image2,keyPoint2,imageDesc2);  
 
	//特征点匹配并显示匹配结果  
	//BruteForceMatcher<L2<float>> matcher;  
	FlannBasedMatcher matcher;
	vector<DMatch> matchePoints;  
	matcher.match(imageDesc1,imageDesc2,matchePoints,Mat());
 
	//提取强特征点
	double minMatch=1;
	double maxMatch=0;
	for(int i=0;i<matchePoints.size();i++)
	{
		//匹配值最大最小值获取
		minMatch=minMatch>matchePoints[i].distance?matchePoints[i].distance:minMatch;
		maxMatch=maxMatch<matchePoints[i].distance?matchePoints[i].distance:maxMatch;
	}
	//最大最小值输出
	cout<<"最佳匹配值是: "<<minMatch<<endl;
	cout<<"最差匹配值是: "<<maxMatch<<endl;
 
	//获取排在前边的几个最优匹配结果
	vector<DMatch> goodMatchePoints;
	for(int i=0;i<matchePoints.size();i++)
	{
		if(matchePoints[i].distance<minMatch+(maxMatch-minMatch)/2)
		{
			goodMatchePoints.push_back(matchePoints[i]);
		}
	}
 
	//绘制最优匹配点
	Mat imageOutput;
	drawMatches(image01,keyPoint1,image02,keyPoint2,goodMatchePoints,imageOutput,Scalar::all(-1),
		Scalar::all(-1),vector<char>(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); 	
	imshow("Mathch Points",imageOutput);  
	waitKey();  
	return 0;  
}

 

 

 

 

 

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值