在前面三篇教程中的几种角检测方法,比如harris角检测,都是旋转无关的,即使我们转动图像,依然能检测出角的位置,但是图像缩放后,harris角检测可能会失效,比如下面的图像,图像放大之前可以检测出为harris角,但是图像放大后,则变成了边,不能检测出角了。所以,harris角是缩放相关的。
在paper Distinctive Image Features from Scale-Invariant Keypoints中,D.Lowe提出了SIFT算法,该算法是缩
放无关的。
sift算法原理参考下面两篇链接。
论文的原文可见:
OpenCV中使用sift特征的代码如下:
// Read input image image= cv::imread("../church01.jpg",0);
keypoints.clear(); // Construct the sift feature detector object cv::SiftFeatureDetector sift( 0.03, // feature threshold 10.); // threshold to reduce // sensitivity to lines
// Detect the SURF features sift.detect(image,keypoints);
cv::drawKeypoints(image,keypoints,featureImage,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
// Display the corners cv::namedWindow("SIFT Features"); cv::imshow("SIFT Features",featureImage);
surf算法可以看作加速的sift算法。原理参考
opencv中使用surf的代码为:
// Read input image cv::Mat image= cv::imread("../church03.jpg",0); // vector of keypoints std::vector<cv::KeyPoint> keypoints; keypoints.clear(); // Construct the SURF feature detector object cv::SurfFeatureDetector surf(2500); // Detect the SURF features surf.detect(image,keypoints);
cv::Mat featureImage; cv::drawKeypoints(image,keypoints,featureImage,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
// Display the corners cv::namedWindow("SURF Features"); cv::imshow("SURF Features",featureImage);
完整代码:工程FirstOpenCV50