opencv源码学习: getStructuringElement函数;
getStructuringElement函数归属于形态学,可以建立指定大小、形状的结构;
原型:
/** @brief Returns a structuring element of the specified size and shape for morphological operations.The function constructs and returns the structuring element that can be further passed to cv::erode, cv::dilate or cv::morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as the structuring element.@param shape Element shape that could be one of cv::MorphShapes @param ksize Size of the structuring element. @param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor position. In other cases the anchor just regulates how much the result of the morphological operation is shifted.*/ CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1));
源码解析:
cv::Mat cv::getStructuringElement(int shape, Size ksize, Point anchor) {int i, j;int r = 0, c = 0;double inv_r2 = 0;CV_Assert( shape == MORPH_RECT || shape == MORPH_CROSS || shape == MORPH_ELLIPSE ); //目前支持三种形状的单元创建: 矩形, 十字形, 椭圆形;anchor = normalizeAnchor(anchor, ksize); //当默认为-1,-1时, 计算anchor;if( ksize == Size(1,1) ) //当给定大小为1,1时,表明是一个点, 可以用矩形来表示;shape = MORPH_RECT;if( shape == MORPH_ELLIPSE ) //椭圆;{r = ksize.height/2;c = ksize.width/2;inv_r2 = r ? 1./((double)r*r) : 0;}Mat elem(ksize, CV_8U);for( i = 0; i < ksize.height; i++ ) //对每一行,计算0,1的范围;{uchar* ptr = elem.ptr(i);int j1 = 0, j2 = 0;if( shape == MORPH_RECT || (shape == MORPH_CROSS && i == anchor.y) ) //矩形,或十字y锚点时 j2为ksize.width;j2 = ksize.width;else if( shape == MORPH_CROSS )j1 = anchor.x, j2 = j1 + 1;else //椭圆;{int dy = i - r;if( std::abs(dy) <= r ){int dx = saturate_cast<int>(c*std::sqrt((r*r - dy*dy)*inv_r2)); //计算得到x的偏移;j1 = std::max( c - dx, 0 );j2 = std::min( c + dx + 1, ksize.width );}}for( j = 0; j < j1; j++ ) //从这三个for可以看出, (0,j1)之间为 0, (j1, j2)之间为1, (j2, ksize.width)之间为0;ptr[j] = 0;for( ; j < j2; j++ )ptr[j] = 1;for( ; j < ksize.width; j++ )ptr[j] = 0;}return elem; }
转载于:https://www.cnblogs.com/yinwei-space/p/9833294.html
opencv源码学习: getStructuringElement函数;相关推荐
- Python源码学习:Python函数浅析-函数闭包
Python源码分析 本文环境python2.5系列 参考书籍<<Python源码剖析>> 上一篇分析了函数参数的分析后,本文分析函数闭包的实现.函数闭包即函数定义和函数表达式 ...
- Python源码学习:Python函数浅析-有参函数
Python源码分析 本文环境python2.5系列 参考书籍<<Python源码剖析>> 继续上一篇无参函数的调用后,本文将分析Python中的有参函数的大致流程,在Pyth ...
- Python源码学习:Python函数浅析-无参函数
Python源码分析 本文环境python2.5系列 参考书籍<<Python源码剖析>> 本文会大致分析一下Python中的函数机制.在Python中,函数是一个比较重要的类 ...
- OpenCv源码解读1-imread函数
前言: 笔者c++水平不高,仅作笔记,不喜勿喷 源代码: 1.函数的两个参数,一个是filename文件路径,一个是flag为图片类型,读取jpg彩图的时候默认为1. 2.在代码的第一行调用了CV_T ...
- opencv源码学习漫水填充
漫水填充就是一种用特定颜色填充连通区域,通过设置可连通像素的上下限以及连通方式达到不同的填充效果的方法.简单来说就是自动选中了和种子点相连的区域,接着将该区域替换成指定的颜色,漫谁填充也可以用来从输入 ...
- C 源码学习——memcpy函数
#include <cruntime.h> #include <string.h>#pragma function(memcpy) /* memcpy()用来拷贝src所指的内 ...
- ThinkPHP源码学习 data_to_xml函数 数据转成xml格式
/** * 数据XML编码 * @param mixed $data 数据 * @param string $item 数字索引时的节点名称 * @param string $id 数字 ...
- 如何学习opencv源码
如何学习opencv源码 当你在使用opencv时,看到一个函数有没有想去了解他的源码,而又无从下手?这里我将带你脱离这种尴尬的境遇! 面对这个问题,我自己也查找过许多的资料,网上有这样一种做法,步骤 ...
- postgresql源码学习(27)—— 事务日志⑦-日志落盘上层函数 XLogFlush
一. 预备知识 1. XLOG什么时候需要落盘 事务commit之前 log buffer被覆盖之前 后台进程定期落盘 2. 两个核心结构体 这两个结构体定义代码在xlog.c,它们在日志落盘过程中非 ...
最新文章
- Resource entery xx is already defined
- 软件需求工程与UML建模——第九组原型系统总结
- 个人数据上云怎么办?树莓派+kodexplorer为你造云
- Nginx handler模块
- C#LeetCode刷题-堆
- 实验1 数字图像处理的MATLAB基础,《数字图像处理(实验部分)》实验1_数字图像处理中MATLAB使用基础...
- 使用cdn和npm引入的区别_中央空调和新风系统有什么区别?有必要一起装吗?
- MS-SQL中创建索引
- 给 WordPress 博客添加 Tabs 标签切换功能
- UVA10879 Code Refactoring【因子+暴力】
- Ubuntu下如何安装Dynamips
- 数字孪生CIM智慧城市BIM,城市cim可视化解决方案公司
- 用Python对全国火车站数量进行分析,发现东北三省竟然占了2成
- 3dsmax展uv_TexTools|3dmax展UV插件(TexTools for 3ds Max)下载v4.10免费版 - 欧普软件下载
- java面试简历精通n_Java简历与面试
- css层叠优先级,css优先级和层叠(示例代码)
- 投资理财--动态市盈率静态市盈率 整理
- 在微软官方网站”满速”下载Windows10最新系统镜像方法。
- 推荐系统之用户标签,以及基于标签的算法
- MySQL的SQL解析器是干什么的?底层原理是什么?
热门文章
- /bin/sh^M:损坏的解释器: 没有那个文件或目录
- Linux 最新配置***
- LeetCode 5364. 按既定顺序创建目标数组
- cnn加工是什么意思_天秤座R-CNN:全面平衡的目标检测器
- python循环结构代码_Python --- 程序的循环结构
- 2020 ccf推荐中文期刊_中国计算机学会推荐中文期刊目录,让业内学者不再盲目投稿...
- android图灵机器人教程,简单的调用图灵机器人
- asp/php招聘,招聘ASP与PHP相关岗位的笔经
- mysql jpa 正则_Spring Data JPA 实例查询
- 1024乘风破浪季,3本好书助你平步青云