OpenCV教程(47) sift特征和surf特征

     在前面三篇教程中的几种角检测方法,比如harris角检测,都是旋转无关的,即使我们转动图像,依然能检测出角的位置,但是图像缩放后,harris角检测可能会失效,比如下面的图像,图像放大之前可以检测出为harris角,但是图像放大后,则变成了边,不能检测出角了。所以,harris角是缩放相关的。

image

     在paper Distinctive Image Features from Scale-Invariant Keypoints中D.Lowe提出了SIFT算法,该算法是缩

放无关的。

sift算法原理参考下面两篇链接。

http://blog.csdn.net/cserchen/article/details/5606859

http://wenku.baidu.com/view/2e1f33b665ce050876321362.html

论文的原文可见:http://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf

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);

image

surf算法可以看作加速的sift算法。原理参考http://wenku.baidu.com/view/1f66acf3f61fb7360b4c65ad.html

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);

image

完整代码:工程FirstOpenCV50

posted on   迈克老狼2012  阅读(2819)  评论(0编辑  收藏  举报

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示