原文:

http://blog.csdn.net/zhaocj/article/details/45198965

DenseFeatureDetector可以生成具有一定密度和规律分布的图像特征点,它主要用于3D VIZ。

DenseFeatureDetector的原理是,把输入图像分割成大小相等的网格,每一个网格提取一个像素作为特征点。类似于图像尺度金字塔,该方法也可以生成不同层图像的特征点,每一层图像所分割的网格大小是不同的,即表示各层的尺度不同。

下面我们就来分析它的源码。

DenseFeatureDetector类的构造函数:

[cpp] view plain copy print?

  1. DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featureScaleLevels,
  2. float _featureScaleMul, int _initXyStep,
  3. int _initImgBound, bool _varyXyStepWithScale,
  4. bool _varyImgBoundWithScale ) :
  5. initFeatureScale(_initFeatureScale), featureScaleLevels(_featureScaleLevels),
  6. featureScaleMul(_featureScaleMul), initXyStep(_initXyStep), initImgBound(_initImgBound),
  7. varyXyStepWithScale(_varyXyStepWithScale), varyImgBoundWithScale(_varyImgBoundWithScale)
  8. {}

DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featureScaleLevels,float _featureScaleMul, int _initXyStep,int _initImgBound, bool _varyXyStepWithScale,bool _varyImgBoundWithScale ) :initFeatureScale(_initFeatureScale), featureScaleLevels(_featureScaleLevels),featureScaleMul(_featureScaleMul), initXyStep(_initXyStep), initImgBound(_initImgBound),varyXyStepWithScale(_varyXyStepWithScale), varyImgBoundWithScale(_varyImgBoundWithScale)
{}

initFeatureScale表示初始图像层特征点的尺度,默认为1

featureScaleLevels表示需要构建多少层图像,默认为1

featureScaleMul表示各层图像之间参数的比例系数,该系数等于相邻两层图像之间的网格宽度之比,尺度之比,以及预留边界宽度之比,默认为0.1

initXyStep表示初始图像层的网格宽度,默认为6

initImgBound表示初始图像层的预留边界宽度,默认为0

varyXyStepWithScale表示各层图像是否进行网格宽度的调整,如果为false,则表示各层图像网格宽度都是initXyStep,如果为true,则表示各层图像网格宽度不等,它们之间的比例系数为featureScaleMul,默认为true

varyImgBoundWithScale表示各层图像是否进行预留边界宽度的调整,如果为false,则表示各层图像预留边界宽度都是initImgBound,如果为true,则表示各层图像预留边界宽度不等,它们之间的比例系数为featureScaleMul,默认为false

下面是检测特征点函数detectImpl:

[cpp] view plain copy print?

  1. void DenseFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask ) const
  2. {
  3. // curScale表示当前层图像特征点的尺度
  4. float curScale = static_cast<float>(initFeatureScale);
  5. //curStep表示当前层图像的网格宽度
  6. int curStep = initXyStep;
  7. //curBound表示当前层图像的预留边界宽度
  8. int curBound = initImgBound;
  9. //遍历各层图像
  10. for( int curLevel = 0; curLevel < featureScaleLevels; curLevel++ )
  11. {
  12. //遍历当前层图像的所有网格,图像四周的预留边界处是没有网格的,横、纵坐标的步长就是网格的宽度
  13. for( int x = curBound; x < image.cols - curBound; x += curStep )
  14. {
  15. for( int y = curBound; y < image.rows - curBound; y += curStep )
  16. {
  17. //把网格的左上角坐标处的像素作为该网格的特征点,并保存
  18. keypoints.push_back( KeyPoint(static_cast<float>(x), static_cast<float>(y), curScale) );
  19. }
  20. }
  21. //调整下一层图像特征点的尺度
  22. curScale = static_cast<float>(curScale * featureScaleMul);
  23. //如果varyXyStepWithScale为true,则调整下一层图像的网格宽度
  24. if( varyXyStepWithScale ) curStep = static_cast<int>( curStep * featureScaleMul + 0.5f );
  25. //如果varyImgBoundWithScale为true,则调整下一层图像的预留边界宽度
  26. if( varyImgBoundWithScale ) curBound = static_cast<int>( curBound * featureScaleMul + 0.5f );
  27. }
  28. //掩码矩阵的特征点处理
  29. KeyPointsFilter::runByPixelsMask( keypoints, mask );
  30. }

void DenseFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask ) const
{// curScale表示当前层图像特征点的尺度float curScale = static_cast<float>(initFeatureScale);//curStep表示当前层图像的网格宽度int curStep = initXyStep;//curBound表示当前层图像的预留边界宽度int curBound = initImgBound;//遍历各层图像for( int curLevel = 0; curLevel < featureScaleLevels; curLevel++ ){//遍历当前层图像的所有网格,图像四周的预留边界处是没有网格的,横、纵坐标的步长就是网格的宽度for( int x = curBound; x < image.cols - curBound; x += curStep ){for( int y = curBound; y < image.rows - curBound; y += curStep ){//把网格的左上角坐标处的像素作为该网格的特征点,并保存keypoints.push_back( KeyPoint(static_cast<float>(x), static_cast<float>(y), curScale) );}}//调整下一层图像特征点的尺度curScale = static_cast<float>(curScale * featureScaleMul);//如果varyXyStepWithScale为true,则调整下一层图像的网格宽度if( varyXyStepWithScale ) curStep = static_cast<int>( curStep * featureScaleMul + 0.5f );//如果varyImgBoundWithScale为true,则调整下一层图像的预留边界宽度if( varyImgBoundWithScale ) curBound = static_cast<int>( curBound * featureScaleMul + 0.5f );}//掩码矩阵的特征点处理KeyPointsFilter::runByPixelsMask( keypoints, mask );
}

下面给出一个具体的应用实例:

[cpp] view plain copy print?

  1. #include "opencv2/core/core.hpp"
  2. #include "highgui.h"
  3. #include "opencv2/imgproc/imgproc.hpp"
  4. #include "opencv2/features2d/features2d.hpp"
  5. #include "opencv2/nonfree/nonfree.hpp"
  6. using namespace cv;
  7. //using namespace std;
  8. int main(int argc, char** argv)
  9. {
  10. Mat img = imread("box_in_scene.png"), img1;;
  11. cvtColor( img, img1, CV_BGR2GRAY );
  12. DenseFeatureDetector dense;
  13. vector<KeyPoint> key_points;
  14. Mat output_img;
  15. dense.detect(img1,key_points,Mat());
  16. drawKeypoints(img, key_points, output_img, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
  17. namedWindow("DENSE");
  18. imshow("DENSE", output_img);
  19. waitKey(0);
  20. return 0;
  21. }

图像局部特征(十七)--DenseFeature相关推荐

  1. 一文读懂图像局部特征点检测算法

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自|新机器视觉 研究图像特征检测已经有一段时间了,图像特征检 ...

  2. 图像局部特征(二十)--Textons

    转自:http://blog.csdn.net/jzwong/article/details/51815134 标题对应着一篇paper,链接在这里:http://idm.pku.edu.cn/sta ...

  3. 图像局部特征(十八)--BOW

    原文: http://blog.sina.com.cn/s/blog_4cb0b54301014hxu.html Bag of Word, 顾名思义,即将某些Word打包,就像我们经常会把类似的物品装 ...

  4. 图像局部特征(一)--概述

    本文根据下面这篇文章,做下简单修改. 原文: http://www.cnblogs.com/ronny/p/4260167.html 研究图像特征检测已经有一段时间了,图像特征检测的方法很多,又加上各 ...

  5. 图像局部特征(二)--Harris角点检测子

     一.角点定义 有定义角点的几段话: 1.角点检测(Corner Detection)是计算机视觉系统中用来获得图像特征的一种方法,广泛应用于运动检测.图像匹配.视频跟踪.三维建模和目标识别等领域 ...

  6. 图像局部特征(八)--斑点检测子SIFT/SURF区别总结

    原文: http://blog.csdn.net/cy513/article/details/4414352 http://blog.csdn.net/jwh_bupt/article/details ...

  7. 图像局部特征(六)--斑点检测之SIFT算法原理总结补充

     原文: http://www.cnblogs.com/cfantaisie/archive/2011/06/14/2080917.html 主要步骤  1).尺度空间的生成:     2).检测 ...

  8. 图像局部特征(五)--斑点检测之SIFT算法原理总结

     尺度不变特征变换匹配算法详解 Scale Invariant Feature Transform(SIFT) Just For Fun zdd  zddmail@gmail.com 对于初学者, ...

  9. 图像局部特征点检测算法综述

    研究图像特征检测已经有一段时间了,图像特征检测的方法很多,又加上各种算法的变形,所以难以在短时间内全面的了解,只是对主流的特征检测算法的原理进行了学习.总体来说,图像特征可以包括颜色特征.纹理特等.形 ...

最新文章

  1. Java类加载机制详解【java面试题】
  2. VPN之DSVPN的介绍
  3. TOMCAT常用优化
  4. JAVA实现美团电影价格抓取(附代码)
  5. andorid 回调的理解
  6. [渝粤教育] 西南科技大学 公共事业管理概论 在线考试复习资料
  7. 哈尔滨工程大学第十四届程序设计竞赛(同步赛)
  8. Swagger UI 可视化 web API 文档、Multiple Dockets with the same group name are not supported.
  9. 现代书法脚本字体Tifany Script
  10. Windows 98 SE
  11. 欠采样和过采样_过采样和欠采样
  12. 数学建模——国赛写作模板篇
  13. 题解:100元买100只鸡,公鸡4元一只,母鸡3元一只,小鸡1元3只,问公鸡,母鸡,小鸡各买了多少只?
  14. US Domain Center 域名抢注服务
  15. .doc文件不显示word图标的解决方法
  16. 多云时代,IBM云计算有什么不同?
  17. Ubuntu18.04+ROS melodic 控制UR5机器人(持续更新)
  18. php ean13,php生成EAN_13标准条形码实例_PHP教程
  19. 859-细谈安全的 HTTPS 协议
  20. macOS安装homebrew cask 问题解决办法

热门文章

  1. Mac使用OpenCV项目步骤
  2. Android5.1 bootchart在Mac使用说明(OK)
  3. get buffer from CMSampleBufferRef
  4. Redis之允许远程访问
  5. MegaRAID Storage Manager RAID管理工具实用教程
  6. php事务基本要素,数据库事务正确执行的四个基本要素
  7. qoq是什么意思的缩写_买鞋多年分不清PE、SE、TD什么意思?建议收藏,这些缩写一定要知道...
  8. tomcat套接字接受失败_07 | What? 还有本地套接字?
  9. unity lookat导致物体颠倒怎么解决_Unity草地交互的实现
  10. Java long传到前台精度损失解决方案