SURF特征点检测的实现如下所示:
SURF函数的用法:
一般create()用minHessian即可
代码:
1 #include <opencv2/opencv.hpp> 2 #include <opencv2/xfeatures2d.hpp> 3 #include <iostream> 4 5 using namespace cv; 6 using namespace cv::xfeatures2d; 7 using namespace std; 8 9 int main(int argc, char** argv) { 10 Mat src = imread("L:/4.jpg", IMREAD_GRAYSCALE); 11 //将读取的图片,读成灰度图片 12 if (src.empty()) { 13 printf("could not load image...\n"); 14 return -1; 15 } 16 namedWindow("input image", CV_WINDOW_AUTOSIZE); 17 imshow("input image", src); 18 19 // SURF特征检测 20 int minHessian = 100; 21 Ptr<SURF> detector = SURF::create(minHessian); //定义一个SURF类型的指针detector,创建最小海深矩阵 22 vector<KeyPoint> keypoints; //定义KeyPoint类型变量 23 detector->detect(src, keypoints, Mat()); //detect函数开始检测 24 25 // 绘制关键点 26 Mat keypoint_img; 27 drawKeypoints(src, keypoints, keypoint_img, Scalar::all(-1), DrawMatchesFlags::DEFAULT); 28 //绘制关键点的函数:1.输入图像 2.检测出的关键点 3.输出图像 4.颜色自动 5.默认为小圆圈 29 imshow("KeyPoints Image", keypoint_img); 30 31 waitKey(0); 32 return 0; 33 }
结果显示: