#include
#include
#include
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
int main(int argc, char** argv) {
Mat src = imread("../path.jpg", IMREAD_GRAYSCALE);
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("src", WINDOW_AUTOSIZE);
imshow("src", src);
//SIFT特征检测
int numFeatures = 400;//定义阈值hessianThreshold为100
Ptr detector = SIFT::create(numFeatures);//定义一个SIFT特征检测器
vector keypoints;//定义关键点
detector->detect(src, keypoints, Mat());//检测
cout << "Total KeyPoints :" << keypoints.size() << endl;//总共有多少个关键点
//绘制关键点
Mat dst;
drawKeypoints(src, keypoints, dst, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
namedWindow("SIFT KeyPoints", WINDOW_AUTOSIZE);
imshow("SIFT KeyPoints", dst);
waitKey(0);
return 0;
}
输出结果:
基于OpenCV4.1.1,函数/功能未实现(此算法已获得专利,不包括在此配置中)…