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. Java-NIO 之 Buffer 与 Channel

    NIO:一种同步非阻塞的 I/O 模型,也是 I/O 多路复用的基础. 同步与异步 同步:发起一个调用后,被调用者未处理完请求之前,调用不返回. 异步:发起一个调用后,立刻得到被调用者的回应表示已接收 ...

  2. rocketmq备忘

    rocketmq unrecognized VM option 'MetaspaceSize=128m' => jdk1.8 JAVA_HOME https://blog.csdn.net/c3 ...

  3. [MyBatis]完整MyBatis CRUD工程

    下载地址:https://files.cnblogs.com/files/xiandedanteng/Person191005.rar pom.xml:这个文件主要是引入依赖 <project ...

  4. 框架-Eureka:百科

    ylbtech-框架-Eureka:百科 1.返回顶部 1. Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中 ...

  5. Thinkphp5 的sesssion在同一个控制器不同的方法无法获取session的原因和对策

    这一段在用thinkPHP5开发微信小程序接口的时候,在同一个控制器一个方法中存入session,在另一个方法中取出session,一直都是无法取出. 查阅各种资料得到原因:thinkPHP5里面的s ...

  6. flutter AnimatedPositioned

    Positioned 的动画版. 只有是 Stack 的 child 时才能工作. 如果 child 的 size 在动画过程会改变,则 AnimatedPositioned 是很好的选择 doubl ...

  7. SQL Server 修改默认实例

    有一台服务器,里面装了两个版本的数据库,一个2008(实例名称为MSSQLSERVER),一个2017(实例名称为MSSQLSERVER01): Sql server 数据库可以安装多个数据库实例,但 ...

  8. HBase管理与监控——强制删除表

    在用phoenix创建Hbase表时,有时会提示创建失败,发现Hbase中又已创建成功, 但这些表在进行enable.disable.drop都无效,也无法删除: hbase(main)::> ...

  9. LeetCode.1175-质数排列(Prime Arrangements)

    这是小川的第413次更新,第446篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第264题(顺位题号是1175).返回1到n的排列数,以使质数处于质数索引(索引从1开始).(请 ...

  10. vue router 报错: Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法

    参考资料:https://blog.csdn.net/zy21131437/article/details/99548983