《SIFT原理与源码分析》系列文章索引:http://www.cnblogs.com/tianyalu/p/5467813.html

OpenCV提供FeatureDetector实现特征检测及匹配

class CV_EXPORTS FeatureDetector
{
public:
virtual ~FeatureDetector();
void detect( const Mat& image, vector<KeyPoint>& keypoints,
const Mat& mask=Mat() ) const;
void detect( const vector<Mat>& images,
vector<vector<KeyPoint> >& keypoints,
const vector<Mat>& masks=vector<Mat>() ) const;
virtual void read(const FileNode&);
virtual void write(FileStorage&) const;
static Ptr<FeatureDetector> create( const string& detectorType );
protected:
...
};

FeatureDetetor是虚类,通过定义FeatureDetector的对象可以使用多种特征检测方法。通过create()函数调用:

Ptr<FeatureDetector> FeatureDetector::create(const string& detectorType);

OpenCV 2.4.3提供了10种特征检测方法:

  • "FAST" – FastFeatureDetector
  • "STAR" – StarFeatureDetector
  • "SIFT" – SIFT (nonfree module)
  • "SURF" – SURF (nonfree module)
  • "ORB" – ORB
  • "MSER" – MSER
  • "GFTT" – GoodFeaturesToTrackDetector
  • "HARRIS" – GoodFeaturesToTrackDetector with Harris detector enabled
  • "Dense" – DenseFeatureDetector
  • "SimpleBlob" – SimpleBlobDetector
图片中的特征大体可分为三种:点特征、线特征、块特征。
FAST算法是Rosten提出的一种快速提取的点特征[1],Harris与GFTT也是点特征,更具体来说是角点特征(参考这里)。
SimpleBlob是简单块特征,可以通过设置SimpleBlobDetector的参数决定提取图像块的主要性质,提供5种:
颜色 By color、面积 By area、圆形度 By circularity、最大inertia (不知道怎么翻译)与最小inertia的比例 By ratio of the minimum inertia to maximum inertia、以及凸性 By convexity.
最常用的当属SIFT,尺度不变特征匹配算法(参考这里);以及后来发展起来的SURF,都可以看做较为复杂的块特征。这两个算法在OpenCV nonfree的模块里面,需要在附件引用项中添加opencv_nonfree243.lib,同时在代码中加入:

initModule_nonfree();

至于其他几种算法,我就不太了解了 ^_^

一个简单的使用演示:

int main()
{ initModule_nonfree();//if use SIFT or SURF
Ptr<FeatureDetector> detector = FeatureDetector::create( "SIFT" );
Ptr<DescriptorExtractor> descriptor_extractor = DescriptorExtractor::create( "SIFT" );
Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create( "BruteForce" );
if( detector.empty() || descriptor_extractor.empty() )
throw runtime_error("fail to create detector!"); Mat img1 = imread("images\\box_in_scene.png");
Mat img2 = imread("images\\box.png"); //detect keypoints;
vector<KeyPoint> keypoints1,keypoints2;
detector->detect( img1, keypoints1 );
detector->detect( img2, keypoints2 );
cout <<"img1:"<< keypoints1.size() << " points img2:" <<keypoints2.size()
<< " points" << endl << ">" << endl; //compute descriptors for keypoints;
cout << "< Computing descriptors for keypoints from images..." << endl;
Mat descriptors1,descriptors2;
descriptor_extractor->compute( img1, keypoints1, descriptors1 );
descriptor_extractor->compute( img2, keypoints2, descriptors2 ); cout<<endl<<"Descriptors Size: "<<descriptors2.size()<<" >"<<endl;
cout<<endl<<"Descriptor's Column: "<<descriptors2.cols<<endl
<<"Descriptor's Row: "<<descriptors2.rows<<endl;
cout << ">" << endl; //Draw And Match img1,img2 keypoints
Mat img_keypoints1,img_keypoints2;
drawKeypoints(img1,keypoints1,img_keypoints1,Scalar::all(-),);
drawKeypoints(img2,keypoints2,img_keypoints2,Scalar::all(-),);
imshow("Box_in_scene keyPoints",img_keypoints1);
imshow("Box keyPoints",img_keypoints2); descriptor_extractor->compute( img1, keypoints1, descriptors1 );
vector<DMatch> matches;
descriptor_matcher->match( descriptors1, descriptors2, matches ); Mat img_matches;
drawMatches(img1,keypoints1,img2,keypoints2,matches,img_matches,Scalar::all(-),CV_RGB(,,),Mat(),); imshow("Mathc",img_matches);
waitKey();
return ;
}

特征检测结果如图:

Box_in_scene

Box

特征点匹配结果:

Match

另一点需要一提的是SimpleBlob的实现是有Bug的。不能直接通过 Ptr<FeatureDetector> detector = FeatureDetector::create("SimpleBlob");  语句来调用,而应该直接创建 SimpleBlobDetector的对象:

        Mat image = imread("images\\features.jpg");
Mat descriptors;
vector<KeyPoint> keypoints;
SimpleBlobDetector::Params params;
//params.minThreshold = 10;
//params.maxThreshold = 100;
//params.thresholdStep = 10;
//params.minArea = 10;
//params.minConvexity = 0.3;
//params.minInertiaRatio = 0.01;
//params.maxArea = 8000;
//params.maxConvexity = 10;
//params.filterByColor = false;
//params.filterByCircularity = false;
SimpleBlobDetector blobDetector( params );
blobDetector.create("SimpleBlob");
blobDetector.detect( image, keypoints );
drawKeypoints(image, keypoints, image, Scalar(,,));

以下是SimpleBlobDetector按颜色检测的图像特征:

[1] Rosten. Machine Learning for High-speed Corner Detection, 2006

本文转自:http://blog.csdn.net/xiaowei_cqu/article/details/8652096

【OpenCV】特征检测器 FeatureDetector的更多相关文章

  1. OpenCV特征点检测------ORB特征

    OpenCV特征点检测------ORB特征 ORB是是ORiented Brief的简称.ORB的描述在下面文章中: Ethan Rublee and Vincent Rabaud and Kurt ...

  2. python+OpenCV 特征点检测

    1.Harris角点检测 Harris角点检测算法是一个极为简单的角点检测算法,该算法在1988年就被发明了,算法的主要思想是如果像素周围显示存在多于一个方向的边,我们认为该点为兴趣点.基本原理是根据 ...

  3. OpenCV特征点检测——Surf(特征点篇)&flann

    学习OpenCV--Surf(特征点篇)&flann 分类: OpenCV特征篇计算机视觉 2012-04-20 21:55 19887人阅读评论(20)收藏举报 检测特征 Surf(Spee ...

  4. OpenCV特征点检测

    特征点检测 目标 在本教程中,我们将涉及: 使用 FeatureDetector 接口来发现感兴趣点.特别地: 使用 SurfFeatureDetector 以及它的函数 detect 来实现检测过程 ...

  5. OpenCV特征点检测——ORB特征

            ORB算法 目录(?)[+] 什么是ORB 如何解决旋转不变性 如何解决对噪声敏感的问题 关于尺度不变性 关于计算速度 关于性能 Related posts 什么是ORB 七 4 Ye ...

  6. OpenCV特征点检测匹配图像-----添加包围盒

    最终效果: 其实这个小功能非常有用,甚至加上只有给人感觉好像人脸检测,目标检测直接成了demo了,主要代码如下: // localize the object std::vector<Point ...

  7. OpenCV特征点检测算法对比

    识别算法概述: SIFT/SURF基于灰度图, 一.首先建立图像金字塔,形成三维的图像空间,通过Hessian矩阵获取每一层的局部极大值,然后进行在极值点周围26个点进行NMS,从而得到粗略的特征点, ...

  8. OpenCV特征点检测------Surf(特征点篇)

    Surf(Speed Up Robust Feature) Surf算法的原理                                                              ...

  9. OpenCV特征点提取----Fast特征

    1.FAST(featuresfrom accelerated segment test)算法 http://blog.csdn.net/yang_xian521/article/details/74 ...

随机推荐

  1. Java EE平台介绍(译)

    Java EE平台介绍 2.1 企业应用总览 这一部分将对企业应用及其设计和开发进行简单介绍. 就像之前说的,Java EE 平台是为了帮助开发者开发大规模.多层次.可伸缩.服务可靠.网络安全的应用而 ...

  2. Maven私库

    <server> <id>releases</id> <username>admin</username> <password> ...

  3. 420. Count and Say【LintCode java】

    Description The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, ...

  4. HDU 6438

    Problem Description The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1 ...

  5. 关闭会声会影2018提示UEIP.dll找不到指定模块

    最近有一些会声会影2018用户反映在关闭后弹出UEIP.dll错误,不知道该怎么办才好,针对这个问题,小编下面为大家介绍下解决方法. 原因分析 出现这个错误跟会声会影安装路径有中文字符是密切相关的,导 ...

  6. cmake-cmake.1-3.11.4机翻

    指数 下一个 | 上一个 | CMake » git的阶段 git的主 最新发布的 3.13 3.12 3.11.4 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 ...

  7. MySQL 中的数据类型介绍

    1.MySQL 数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 2.数值类型(12) 2.1. ...

  8. javascript event对象操作

    js代码: $(".leads_detail").click(function(e){ e = e || event; var t = e.target || e.srcEleme ...

  9. Programming Protocol-Independent Packet Processors

    引言 OpenFlow协议固定的包头域数目,使得南向协议过于死板. P4可以实现自定义包头,增加灵活性. P4是OpenFlow未来发展的方向. We propose P4 as a strawman ...

  10. 一些有趣的erlang项目

    这里会收集一些erlang项目,有需可以转. erlang-bookmarks Scaling Erlang High Performance Erlang - Finding Bottlenecks ...