【CS】尺度不变特征变换匹配算法SIFT

尺度不变特征变换匹配算法SIFT

e-mail:chentravelling@163.com

SIFT算法
SIFT算法即尺度不变特征转换(Scale-invariant feature transform),本文重点不阐述该算法的原理,想要了解原理的朋友可以参考另一篇比较详细的CSDN文章(戳这里查看),该篇文章讲述的比较详细。
SIFT算法主要分为五个步骤:
(1)建立尺度空间,检测图像极值点:通过高斯微分函数建立尺度空间,通过高斯差分尺度空间(DoG scale-space)检测图像局部极值点。
(2)去除不稳定点,确定关键点:不稳定点主要为不稳定的边缘点和低对比度的关键点,Dacid G.Lowe通过拟合二阶微分方程的方法排除低对比度点,同时可采用Harris角点检测方法去除不稳定的边缘点。
(3)确定关键点的方向:主要原理是统计关键点领域所有的梯度方向直方图,以直方图中最大值作为该关键点的主方向,同时为了提高后续匹配的鲁棒性,将直方图中峰值超过主峰80%的方向作为该关键点的辅方向。
(4)提取关键点描述符
(5)关键点匹配:才用特征向量之间的欧氏距离评估关键点之间的相似性程度。那么这里会通过一个预设的阈值进行过滤,阈值的设置直接影响到匹配点的数量和精确性。一般阈值的选择为0.7~0.8之间。
为了更好的看到SIFT算法的效果,可以实践一下。
C++代码
#include <opencv2/opencv.hpp>
#include <istream>

using namespace std;
using namespace cv;
int main()
{
	//read the two input images
	Mat image1 = imread("image1.jpg");
	Mat image2 = imread("image2.jpg");
	//if failed
	if(image1.empty()||image2.empty())
	{
		cout<<"error,the image is not exist"<<endl;
		return -1;
	}
	//difine a sift detector
	SiftFeatureDetector siftDetector;
	//store key points
	vector<KeyPoint> keypoint1,keypoint2;
	//detect image with SIFT,get key points
	siftDetector.detect(image1,keypoint1);
	Mat outImage1;
	//draw key points at the out image and show to the user
	drawKeypoints(image1,keypoint1,outImage1,Scalar(255,0,0));

	imshow("original_image1",image1);
	imshow("sift_image1",outImage1);
	
	Mat outImage2;
	
	siftDetector.detect(image2,keypoint2);
	drawKeypoints(image2,keypoint2,outImage2,Scalar(255,0,0));

	imshow("sift_image2.jpg",outImage2);
	//imwrite("sift_result2.jpg",outImage2);
	//store 10 keypoints in order to watch the effect clearly
	vector<KeyPoint> keypoint3,keypoint4;
	for(int i=0;i<10;i++)
	{
		keypoint3.push_back(keypoint1[i]);
		keypoint4.push_back(keypoint2[i]);
	}
	// difine a sift descriptor extractor
	SiftDescriptorExtractor extractor;
	//store the descriptor of each image
	Mat descriptor1,descriptor2;
	BruteForceMatcher<L2<float>> matcher;

	vector<DMatch> matches;
	Mat img_matches;
	//compute the descriptor of each image
	extractor.compute(image1,keypoint3,descriptor1);
	extractor.compute(image2,keypoint4,descriptor2);
	//match
	matcher.match(descriptor1,descriptor2,matches);
	//show the result
	drawMatches(image1,keypoint3,image2,keypoint4,matches,img_matches,Scalar(255,0,0));
	imshow("matches",img_matches);
	//store the match_image
	//imwrite("matches.jpg",img_matches);

	waitKey(0);
	return 0;
}

运行效果
依次为:原图,原图sift后,原图经缩放旋转再sift后,匹配结果




为了清晰看出匹配点之间的连线关系,程序中只是从每一幅图的SIFT关键点中选择了10个关键点,而且是下标相对应的10个点,从理论上来讲,可能存在一些问题,就是这些点实际上本就不是对应的匹配点,所以可能这也是造成匹配结果有误的原因。
那么如果我们把所有的关键点都进行匹配,效果如下:

依次为:原图和原图&缩放旋转后匹配,原图和原图&缩放后匹配。



从这两张匹配后的图中也可以看出,同样是存在错误匹配的。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值