1.

inline Mat::Mat(int _rows, int _cols, int _type) : size(&rows)
{
initEmpty();//将data、cols、rows等初始化为0
create(_rows, _cols, _type);
}

2.

inline Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) : size(&rows)
{
initEmpty();
create(_rows, _cols, _type);
*this = _s;//给矩阵像素赋值为_s
}

3.

inline void Mat::create(int _rows, int _cols, int _type)
{
_type &= TYPE_MASK;
if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && data ) //如果cols rows data已经存在,则返回,什么都不用做
return;
int sz[] = {_rows, _cols};
create(2, sz, _type);
}

4.

void Mat::create(int d, const int* _sizes, int _type)
{
int i;
CV_Assert( <= d && _sizes && d <= CV_MAX_DIM && _sizes);
_type = CV_MAT_TYPE(_type); if( data && (d == dims || (d == && dims <= )) && _type == type() )
{
if( d == && rows == _sizes[] && cols == _sizes[] )
return;
for( i = ; i < d; i++ )
if( size[i] != _sizes[i] )
break;
if( i == d && (d > || size[] == ))
return;
} release();
if( d == )
return;
flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL;
setSize(*this, d, _sizes, , true); if( total() > )
{
#ifdef HAVE_TGPU
if( !allocator || allocator == tegra::getAllocator() ) allocator = tegra::getAllocator(d, _sizes, _type);
#endif
if( !allocator )//如果没有分配内存,则去分配, 否则则用allocate 把指针指向data就行了,不用重复分配
{
size_t totalsize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
data = datastart = (uchar*)fastMalloc(totalsize + (int)sizeof(*refcount));
refcount = (int*)(data + totalsize);
*refcount = ; //引用计数
}
else
{
#ifdef HAVE_TGPU
try
{
allocator->allocate(dims, size, _type, refcount, datastart, data, step.p);
CV_Assert( step[dims-] == (size_t)CV_ELEM_SIZE(flags) );
}catch(...)
{
allocator = ;
size_t totalSize = alignSize(step.p[]*size.p[], (int)sizeof(*refcount));
data = datastart = (uchar*)fastMalloc(totalSize + (int)sizeof(*refcount));
refcount = (int*)(data + totalSize);
*refcount = ;
}
#else
allocator->allocate(dims, size, _type, refcount, datastart, data, step.p);
CV_Assert( step[dims-] == (size_t)CV_ELEM_SIZE(flags) );
#endif
}
} finalizeHdr(*this);
}

Mat 的拷贝构造函数

inline Mat::Mat(const Mat& m)
: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),
refcount(m.refcount), datastart(m.datastart), dataend(m.dataend),
datalimit(m.datalimit), allocator(m.allocator), size(&rows)
{
if( refcount )
CV_XADD(refcount, );
if( m.dims <= )
{
step[] = m.step[]; step[] = m.step[];
}
else
{
dims = ;
copySize(m);
}
}

【Opencv 源码剖析】 一、 create函数的更多相关文章

  1. 5.2【Linux 内核网络协议栈源码剖析】socket 函数剖析 ☆☆☆

    深度剖析网络协议栈中的 socket 函数,可以说是把前面介绍的串联起来,将网络协议栈各层关联起来. 应用层 FTP SMTP HTTP ... 传输层 TCP UDP 网络层 IP ICMP ARP ...

  2. opencv源码学习: getStructuringElement函数;

    getStructuringElement函数归属于形态学,可以建立指定大小.形状的结构: 原型: /** @brief Returns a structuring element of the sp ...

  3. 【opencv 源码剖析】 三、 morphOp 数学形态学滤波函数, 腐蚀和膨胀就是通过这个函数得到的

    // //_kernel : 形态学滤波的核 //anchor: 锚点再滤波核的位置 //iterations: 迭代次数 static void morphOp( int op, InputArra ...

  4. STL源码剖析之_allocate函数

    SGI STL提供的标准std::allocator中的_allocate函数代码如下: template<class T> inline T* _allocate(ptrdiff_t s ...

  5. 【opencv 源码剖析】 四、 Mat的赋值构造函数 和 拷贝构造函数

    1.赋值构造函数 右值引用 inline Mat& Mat::operator = (Mat&& m) { if (this == &m) return *this; ...

  6. 菜鸟nginx源码剖析 框架篇(一) 从main函数看nginx启动流程(转)

    俗话说的好,牵牛要牵牛鼻子 驾车顶牛,处理复杂的东西,只要抓住重点,才能理清脉络,不至于深陷其中,不能自拔.对复杂的nginx而言,main函数就是“牛之鼻”,只要能理清main函数,就一定能理解其中 ...

  7. c++ stl源码剖析学习笔记(一)uninitialized_copy()函数

    template <class InputIterator, class ForwardIterator>inline ForwardIterator uninitialized_copy ...

  8. 《python解释器源码剖析》第12章--python虚拟机中的函数机制

    12.0 序 函数是任何一门编程语言都具备的基本元素,它可以将多个动作组合起来,一个函数代表了一系列的动作.当然在调用函数时,会干什么来着.对,要在运行时栈中创建栈帧,用于函数的执行. 在python ...

  9. 豌豆夹Redis解决方案Codis源码剖析:Dashboard

    豌豆夹Redis解决方案Codis源码剖析:Dashboard 1.不只是Dashboard 虽然名字叫Dashboard,但它在Codis中的作用却不可小觑.它不仅仅是Dashboard管理页面,更 ...

随机推荐

  1. box-sizing Bootstrap

    https://getbootstrap.com/docs/4.0/getting-started/introduction/#box-sizing Box-sizing For more strai ...

  2. 只要你用atom修改后保存代码文件的时候,你在chrome上的页面就会自动刷新。

    学习html和css的时候Ctrl+s 以后预览网页需要手动刷新 现在不用了 给chrome安装安装LivePage这个插件. 只要你用atom修改后保存代码文件的时候,你在chrome上的页面就会自 ...

  3. ubantu下docker安装

    开始安装 由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本: sudo apt-get remove docker docker-engine docker-ce docke ...

  4. react封装基于axios的API请求

    一.最近做的一个后台管理项目,基于antd-pro做的,需要封装基于axios请求,便于开发,直接上代码. import axios from 'axios'; export const Method ...

  5. 数据分析 - Excel 函数, 技巧, 分析工具

    数据分析工具使用场景 函数 分类 文本清洗函数 FIND - 查找 find 函数查询指定位置的某字符的的位置 快捷键 : 选中后双击右下角的 + 可以快速生成当前一列结果 FIND("查询 ...

  6. 一百一十三:CMS系统之前台注册界面

    html {% from 'common/_macros.html' import static %}<!DOCTYPE html><html lang="en" ...

  7. Django View视图

    视图view 一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受Web请求并且返回Web响应.响应可以是一张网页的HTML内容,一个重定向,一个404错误,一个XML文档,或者 ...

  8. python中计时模块timeit的使用方法

    timeit 模块: timeit 模块定义了接受两个参数的 Timer 类.两个参数都是字符串. 第一个参数是你要计时的语句或者函数. 传递给 Timer 的第二个参数是为第一个参数语句构建环境的导 ...

  9. localhost解释

    .localhost解释 localhost意思是只能从本地访问 比如说 kibana的配置文件里面写的是localhost,那就无法从浏览器访问到服务,必须写ip地址才可以从浏览器访问到

  10. spark 1.6.0 安装与配置(spark1.6.0、Ubuntu14.04、hadoop2.6.0、scala2.10.6、jdk1.7)

    前几天刚着实研究spark,spark安装与配置是入门的关键,本人也是根据网上各位大神的教程,尝试配置,发现版本对应最为关键.现将自己的安装与配置过程介绍如下,如有兴趣的同学可以尝试安装.所谓工欲善其 ...