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.csdn.net/abcjennifer/article/details/7639681
http://blog.csdn.net/xiaowei_cqu/article/details/8069548
http://www.cnblogs.com/tornadomeet/archive/2012/08/16/2643168.html