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

[cpp] view plaincopy
  1. class CV_EXPORTS FeatureDetector
  2. {
  3. public:
  4. virtual ~FeatureDetector();
  5. void detect( const Mat& image, vector<KeyPoint>& keypoints,
  6. const Mat& mask=Mat() ) const;
  7. void detect( const vector<Mat>& images,
  8. vector<vector<KeyPoint> >& keypoints,
  9. const vector<Mat>& masks=vector<Mat>() ) const;
  10. virtual void read(const FileNode&);
  11. virtual void write(FileStorage&) const;
  12. static Ptr<FeatureDetector> create( const string& detectorType );
  13. protected:
  14. ...
  15. };

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

[cpp] view plaincopy
  1. 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,同时在代码中加入:
[cpp] view plaincopy
  1. initModule_nonfree();
至于其他几种算法,我就不太了解了 ^_^

一个简单的使用演示:
[cpp] view plaincopy
  1. int main()
  2. {
  3. initModule_nonfree();//if use SIFT or SURF
  4. Ptr<FeatureDetector> detector = FeatureDetector::create( "SIFT" );
  5. Ptr<DescriptorExtractor> descriptor_extractor = DescriptorExtractor::create( "SIFT" );
  6. Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create( "BruteForce" );
  7. if( detector.empty() || descriptor_extractor.empty() )
  8. throw runtime_error("fail to create detector!");
  9. Mat img1 = imread("images\\box_in_scene.png");
  10. Mat img2 = imread("images\\box.png");
  11. //detect keypoints;
  12. vector<KeyPoint> keypoints1,keypoints2;
  13. detector->detect( img1, keypoints1 );
  14. detector->detect( img2, keypoints2 );
  15. cout <<"img1:"<< keypoints1.size() << " points  img2:" <<keypoints2.size()
  16. << " points" << endl << ">" << endl;
  17. //compute descriptors for keypoints;
  18. cout << "< Computing descriptors for keypoints from images..." << endl;
  19. Mat descriptors1,descriptors2;
  20. descriptor_extractor->compute( img1, keypoints1, descriptors1 );
  21. descriptor_extractor->compute( img2, keypoints2, descriptors2 );
  22. cout<<endl<<"Descriptors Size: "<<descriptors2.size()<<" >"<<endl;
  23. cout<<endl<<"Descriptor's Column: "<<descriptors2.cols<<endl
  24. <<"Descriptor's Row: "<<descriptors2.rows<<endl;
  25. cout << ">" << endl;
  26. //Draw And Match img1,img2 keypoints
  27. Mat img_keypoints1,img_keypoints2;
  28. drawKeypoints(img1,keypoints1,img_keypoints1,Scalar::all(-1),0);
  29. drawKeypoints(img2,keypoints2,img_keypoints2,Scalar::all(-1),0);
  30. imshow("Box_in_scene keyPoints",img_keypoints1);
  31. imshow("Box keyPoints",img_keypoints2);
  32. descriptor_extractor->compute( img1, keypoints1, descriptors1 );
  33. vector<DMatch> matches;
  34. descriptor_matcher->match( descriptors1, descriptors2, matches );
  35. Mat img_matches;
  36. drawMatches(img1,keypoints1,img2,keypoints2,matches,img_matches,Scalar::all(-1),CV_RGB(255,255,255),Mat(),4);
  37. imshow("Mathc",img_matches);
  38. waitKey(10000);
  39. return 0;
  40. }

特征检测结果如图:

Box_in_scene
Box
特征点匹配结果:
Match
另一点需要一提的是SimpleBlob的实现是有Bug的。不能直接通过 Ptr<FeatureDetector> detector = FeatureDetector::create("SimpleBlob");  语句来调用,而应该直接创建 SimpleBlobDetector的对象:
[cpp] view plaincopy
  1. Mat image = imread("images\\features.jpg");
  2. Mat descriptors;
  3. vector<KeyPoint> keypoints;
  4. SimpleBlobDetector::Params params;
  5. //params.minThreshold = 10;
  6. //params.maxThreshold = 100;
  7. //params.thresholdStep = 10;
  8. //params.minArea = 10;
  9. //params.minConvexity = 0.3;
  10. //params.minInertiaRatio = 0.01;
  11. //params.maxArea = 8000;
  12. //params.maxConvexity = 10;
  13. //params.filterByColor = false;
  14. //params.filterByCircularity = false;
  15. SimpleBlobDetector blobDetector( params );
  16. blobDetector.create("SimpleBlob");
  17. blobDetector.detect( image, keypoints );
  18. drawKeypoints(image, keypoints, image, Scalar(255,0,0));

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

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

(转载请注明作者和出处:http://blog.csdn.net/xiaowei_cqu 未经允许请勿用于商业用途)

特征检测器 FeatureDetector相关推荐

  1. OpenCV2.4.4中调用SIFT特征检测器进行图像匹配

    OpenCV中一些相关结构说明: 特征点类: [cpp] view plain copy   class KeyPoint { Point2f  pt;  //坐标 float  size; //特征 ...

  2. 【图像处理】——特征匹配(SIFT特征检测器+FLANN特征匹配方法+KNN近邻最优匹配筛选)——cv.xfeatures2d.SIFT_create()sift.detectAndCompute

    转载请注明地址 目录 1.特征检测和特征匹配方法 (1)特征检测算法 (2)特征匹配算法 (3)各种特征检测算法的比较 2.特征匹配的基本步骤(附带主要的函数) (1)图像预处理--灰度化(模板--查 ...

  3. 非刚性人脸跟踪 —— 面部特征检测器

    本节将用一种表示方法来建立人脸特征检测器,该方法也许是人们认为最简单的模型,即:线性图像模型.由于该算法需表示一个图象块,因此这种面部特征检测器称为块模型( patch model ).该模型在 pa ...

  4. OpenCV —— 特征点检测之 SIFT 特征检测器

    SIFT 原理详解 尺度空间的表示 高斯金字塔的构建 高斯差分金字塔 空间极值点检测 尺度变化的连续性 特征点定位 特征点的精确定位 剔除不稳定的边缘响应点 特征点方向赋值 生成特征描述 SIFT的缺 ...

  5. 目标检测 - 特征检测器比较

    定量比较表明,特征检测器描述符检测大量特征的能力的一般顺序为: ORB>BRISK>SURF>SIFT>AKAZE>KAZE 每个特征点的特征检测描述计算效率的算法顺序为 ...

  6. VLfeat学习(1)——Covariant feature detectors(协变特征检测器)

    VLfeat是一个开源BSD的轻量级的计算机视觉库算法,主要实现了SIFT.MSER.K-means.hierarchical.agglomerative information bottleneck ...

  7. scikit-image库----CENSURE特征检测器(二十二)

    CENSURE特征检测器是一种尺度不变的中心环绕检测器(CENSURE),其性能优于其他检测器,并且能够实时实现. from skimage import data from skimage impo ...

  8. OpenCV3学习(11.5) FAST特征检测器FastFeatureDetector

    简介 FAST特征检测的特点是简单.快速.有效.作者为了在实时帧速率情况下进行高速特征检测,提出FAST特征检测. 相比SIFT.DoG.Harris.SUSAN等比较耗时的特征检测方法,FAST只利 ...

  9. OpenCV3学习(11.7) BRISK特征检测器及BRISK描述符

     BRISK算法一种特征提取算法,也是一种二进制的特征描述算子. 它具有较好的旋转不变性.尺度不变性,较好的鲁棒性等.在图像配准应用中,速度比较:SIFT<SURF<BRISK<FR ...

最新文章

  1. linux下的rman自动备份脚本,LINUX上RMAN自动备份脚本
  2. 迁移学习简介(tranfer learning)
  3. Caffe: Faster-RCNN Python版本配置 (Windows)
  4. python中threading模块详解
  5. JavaWeb:XML总结
  6. linux drbd同步,DRBD数据镜像主备节点同步数据
  7. SQL Server:查找表的生成或顺序
  8. 官方配置要求_电脑配置不够玩赛博朋克?租电脑一个月只要百来元就能玩!
  9. 单层的神经网络使用自定义的损失函数
  10. java 算法基础之三合并排序法
  11. rubyOnRails 开发以及风格指南
  12. Python漫画下载器V2,进行更好的封装,更高效的多线程与刷新机制
  13. 基于asp.net大学生就业管理系统#毕业设计
  14. 高尔顿钉板 matlab,高尔顿钉板试验模拟
  15. 国内云服务器提供商排名(仅供参考)
  16. vscode:解决按英文感叹号!+tab,无法生成html模板框架的问题
  17. hdu2028java-Lowest Common Multiple Plus
  18. PTA 7-80 水仙花数 (20分)
  19. C++ 小白 学习记录15
  20. linux barrier,Linux文件系统的barrier:启用还是禁用

热门文章

  1. 58同城创始人姚劲波:未来十年是中国创业最好机会
  2. 深入理解分布式技术 - 消息队列知识点回顾总结
  3. 深入理解分布式技术 - 消息幂等性如何保障不重复消费
  4. 深入理解分布式技术 - 微服务为什么需要API 网关
  5. 数据存储之SharedPreferences
  6. 信息提醒之对话框(AlertDialog + ProgressDialog)-更新中
  7. Android Q适配
  8. sql 判断分钟是偶数数据_使用SQL交换座位(奇偶数的用法)
  9. anguarjs 上传图片预览_MIUI12 20.10.29更新,新版「模糊预览图」
  10. javascript 数组以及对象的深拷贝方法