SIFT特徵點檢測實現

 

 

 

 

 

 

 

 

 

 

 

 檢測代碼:ios

 

 1 #include <opencv2/opencv.hpp>
 2 #include <opencv2/xfeatures2d.hpp>
 3 #include <iostream>
 4 
 5 using namespace cv;  6 using namespace std;  7 using namespace cv::xfeatures2d;  8 
 9 int main(int argc, char** argv) { 10     Mat src = imread("L:/4.jpg"); 11     if (src.empty()) { 12         printf("could not load image...\n"); 13         return -1; 14  } 15     namedWindow("input image", CV_WINDOW_AUTOSIZE); 16     imshow("input image", src); 17 
18     int numFeatures = 400;    //檢測400個特徵點 
19     Ptr<SIFT> detector = SIFT::create(numFeatures); 20     vector<KeyPoint> keypoints; 21     detector->detect(src, keypoints, Mat());  //開始檢測
22     printf("Total KeyPoints : %d\n", keypoints.size());  //打印keypoints的數量信息
23 
24  Mat keypoint_img; 25     drawKeypoints(src, keypoints, keypoint_img, Scalar::all(-1), DrawMatchesFlags::DEFAULT); 26     //將關鍵點畫到圖上
27     namedWindow("SIFT KeyPoints", CV_WINDOW_AUTOSIZE); 28     imshow("SIFT KeyPoints", keypoint_img); 29 
30     waitKey(0); 31     return 0; 32 }

 

結果:spa

相關文章
相關標籤/搜索