SIFT特征点检测实现

前提是你 提交于 2019-12-01 15:13:55

 

 

 

 

 

 

 

 

 

 

 

 检测代码:

 

 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 }

 

结果:

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!