【OpenCV】特征检测器 FeatureDetector
《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
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的更多相关文章
- OpenCV特征点检测------ORB特征
OpenCV特征点检测------ORB特征 ORB是是ORiented Brief的简称.ORB的描述在下面文章中: Ethan Rublee and Vincent Rabaud and Kurt ...
- python+OpenCV 特征点检测
1.Harris角点检测 Harris角点检测算法是一个极为简单的角点检测算法,该算法在1988年就被发明了,算法的主要思想是如果像素周围显示存在多于一个方向的边,我们认为该点为兴趣点.基本原理是根据 ...
- OpenCV特征点检测——Surf(特征点篇)&flann
学习OpenCV--Surf(特征点篇)&flann 分类: OpenCV特征篇计算机视觉 2012-04-20 21:55 19887人阅读评论(20)收藏举报 检测特征 Surf(Spee ...
- OpenCV特征点检测
特征点检测 目标 在本教程中,我们将涉及: 使用 FeatureDetector 接口来发现感兴趣点.特别地: 使用 SurfFeatureDetector 以及它的函数 detect 来实现检测过程 ...
- OpenCV特征点检测——ORB特征
ORB算法 目录(?)[+] 什么是ORB 如何解决旋转不变性 如何解决对噪声敏感的问题 关于尺度不变性 关于计算速度 关于性能 Related posts 什么是ORB 七 4 Ye ...
- OpenCV特征点检测匹配图像-----添加包围盒
最终效果: 其实这个小功能非常有用,甚至加上只有给人感觉好像人脸检测,目标检测直接成了demo了,主要代码如下: // localize the object std::vector<Point ...
- OpenCV特征点检测算法对比
识别算法概述: SIFT/SURF基于灰度图, 一.首先建立图像金字塔,形成三维的图像空间,通过Hessian矩阵获取每一层的局部极大值,然后进行在极值点周围26个点进行NMS,从而得到粗略的特征点, ...
- OpenCV特征点检测------Surf(特征点篇)
Surf(Speed Up Robust Feature) Surf算法的原理 ...
- OpenCV特征点提取----Fast特征
1.FAST(featuresfrom accelerated segment test)算法 http://blog.csdn.net/yang_xian521/article/details/74 ...
随机推荐
- Struts2(一.基本介绍,环境搭建及需求分析)
Struts2框架开发 前言 开发工具:eclipse struts1:老项目使用较多,维护时需要用到 struts2:新项目使用较多 一.特点 1. 无侵入式设计 struts2 与 struts ...
- VMware安装的Windows10下Docker的安装
1.前言 开启学习Docker之旅,首先在VMware中安装了windows10,因为Docker for windows要Win10专业或者企业版,现在台式机是win7,不想动主机系统.嘻嘻 不过, ...
- 【python 2.7】python读取json数据存入MySQL
同上一篇,只是适配 CentOS+ python 2.7 #python 2.7 # -*- coding:utf-8 -*- __author__ = 'BH8ANK' import json im ...
- 写一个脚本批量转换项目中GB2312编码的文件为UTF-8编码
#!/bin/bash convert_file() { for file in `find .` do if [[ -f $file ]] then if [[ ${file##*.} == lua ...
- Tensorflow - Implement for a Softmax Regression Model on MNIST.
Coding according to TensorFlow 官方文档中文版 import tensorflow as tf from tensorflow.examples.tutorials.mn ...
- django项目中关于跨域CORS
1.使用django-cors-headers扩展,但首先进行安装 2.在配置中添加应用 3.在中间层中设置:“corsheaders.middleware.CorsMiddleware” 4.添加C ...
- Python3 匿名函数
一 匿名函数 lambda函数也叫匿名函数,语法结构如下: lambda x:x+1 x --> 形参 x+1 --> 返回值,相当于return x+1 实例(Python3.0+): ...
- app开发相关
app播放UIWebview 没有声音解决: 设置 allowsInlineMediaPlayback = YES; mediaPlaybackRequiresUserAction = NO
- Python中import的as语法
在Python中,如果import的语句比较长,导致后续引用不方便,可以使用as语法,比如: import dir1.dir2.mod # 那么,后续对mod的引用,都必须是dir1.dir2.mod ...
- scrum立会报告+燃尽图(第三周第七次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2286 项目地址:https://coding.net/u/wuyy694 ...