sift = scale invariant feature transform—— 尺度不变特征变换,具有尺度,旋转,仿射,视角,光照不变性。。
关于sift的特征介绍,已经有很多的blog对其进行简介了,见参考的blog。我也没有将2004年那篇原文精细看完,这里只是提供在opencv中如何实现 sift关键点的检测。
Code:
- #include <iostream>
- #include <opencv2\core\core.hpp>
- #include <opencv2\highgui\highgui.hpp>
- #include <opencv2\highgui\highgui.hpp>
- #include <opencv2\features2d\features2d.hpp>
- #include <opencv2\nonfree\nonfree.hpp> // sift特征在这个头文件中
-
- using namespace std;
- using namespace cv;
-
- int main()
- {
- Mat image = imread("F:\\lena.png", 1);
- if(!image.data)
- {
- cout << "Fail to load image" << endl;
- return 0;
- }
- vector<KeyPoint> keypoints;
- SiftFeatureDetector sift(0.03, 10.0);
- sift.detect(image, keypoints);
- drawKeypoints(image, keypoints, image, Scalar(255,255,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
- namedWindow("sift");
- imshow("sift", image);
- waitKey(0);
- return 0;
- }
Explanation:
<1>sift函数阀值介绍见代码注释
<2>drawKeypoints函数:
(1)设置特征点的颜色时可以赋予一个负值,这将产生有趣的结果,即绘制的圆将拥有不同的随机颜色
(2)绘制标记参数:
- struct DrawMatchesFlags{ enum {
- DEFAULT = 0,
-
- DRAW_OVER_OUTIMG = 1,
- NOT_DRAW_SINGLE_POINTS = 2,
- DRAW_RICH_KEYPOINTS = 4
- };
- };
Result:

参考blog:
http://www.cnblogs.com/cfantaisie/archive/2011/06/14/2080917.html
http://blog.youkuaiyun.com/abcjennifer/article/details/7639681
http://blog.youkuaiyun.com/xiaowei_cqu/article/details/8069548
http://www.cnblogs.com/tornadomeet/archive/2012/08/16/2643168.html