#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <iostream>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
int main(int argc, char** argv) {
Mat src = imread("C:/Users/think/Desktop/opencv3.2/opencv3.2/1.1.2.png");
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("input image", CV_WINDOW_AUTOSIZE);
imshow("input image", src);
int numFeatures = 400;
Ptr<SIFT> detector = SIFT::create(numFeatures);
vector<KeyPoint> keypoints;
detector->detect(src, keypoints, Mat());
printf("Total KeyPoints : %d\n", keypoints.size());
Mat keypoint_img;
drawKeypoints(src, keypoints, keypoint_img, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
namedWindow("SIFT KeyPoints", CV_WINDOW_AUTOSIZE);
imshow("SIFT KeyPoints", keypoint_img);
waitKey(0);
return 0;
}
int numFeatures = 400;
Ptr<SIFT> detector = SIFT::create(numFeatures);
vector<KeyPoint> keypoints; //用来存放keypoints
detector->detect(src, keypoints, Mat());// Mat()不知道干啥用的 是mask;
CV_WRAP static Ptr<SIFT> create( int nfeatures = 0, int nOctaveLayers = 3,
double contrastThreshold = 0.04, double edgeThreshold = 10,
double sigma = 1.6);
nfeatures是SIFI特征点数目,nOctaveLayers是层数,contrastThreshold 是用于极值点(易受噪声) 排除,edgeThreshold 是边缘极值排除,sigma是高斯核;
整个函数实现还是比较清楚的;就是简单的调用。