Sift特徵

sift = scale invariant feature transform—— 尺度不變特徵變換,具有尺度,旋轉,仿射,視角,光照不變性。。

關於sift的特徵介紹,已經有很多的blog對其進行簡介了,見參考的blog。我也沒有將2004年那篇原文精細看完,這裏只是提供在opencv中如何實現 sift關鍵點的檢測。

Code:

  1. #include <iostream>  
  2. #include <opencv2\core\core.hpp>  
  3. #include <opencv2\highgui\highgui.hpp>  
  4. #include <opencv2\highgui\highgui.hpp>  
  5. #include <opencv2\features2d\features2d.hpp>  
  6. #include <opencv2\nonfree\nonfree.hpp>             //  sift特徵在這個頭文件中  
  7.   
  8. using namespace std;  
  9. using namespace cv;  
  10.   
  11. int main()  
  12. {  
  13.     Mat image = imread("F:\\lena.png", 1);  
  14.     if(!image.data)  
  15.     {  
  16.         cout << "Fail to load image" << endl;  
  17.         return 0;  
  18.     }  
  19.     vector<KeyPoint> keypoints;          //  存放關鍵點  
  20.     SiftFeatureDetector sift(0.03, 10.0);   // 其中0.03代表特徵的閥值:用於去除低對比度的關鍵點   10是用於降低直線敏感度的閥值:去除不穩點的邊緣響應點  
  21.     sift.detect(image, keypoints);  
  22.     drawKeypoints(image, keypoints, image, Scalar(255,255,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);  
  23.     namedWindow("sift");  
  24.     imshow("sift", image);  
  25.     waitKey(0);  
  26.     return 0;  
  27. }  

Explanation:

<1>sift函數閥值介紹見代碼註釋

<2>drawKeypoints函數:

(1)設置特徵點的顏色時可以賦予一個負值,這將產生有趣的結果,即繪製的圓將擁有不同的隨機顏色

(2)繪製標記參數:

 

  1. struct DrawMatchesFlags{    enum    {  
  2.         DEFAULT = 0, // 輸出圖像將被創建(Mat::create),  
  3.                      // 只畫出特徵點,而不畫出周圍的circle包含特徵點的大小和方向.  
  4.         DRAW_OVER_OUTIMG = 1, // 輸出圖像將被創建(using Mat::create),匹配點將被畫在輸出圖像的內容上.  
  5.         NOT_DRAW_SINGLE_POINTS = 2, // 單個的點不畫出.  
  6.         DRAW_RICH_KEYPOINTS = 4 // 對每個特徵點周圍的circle,包含特徵點的大小和方向將被畫出.      
  7.     };  
  8. };  

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章