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. 数据库 | Oracle数据库查表空间使用情况

    平时在使用Oracle的时候,如果业务中的数据量激增.数据量变大,很有可能就会有表空间不足的情况,需要重点关注.今天我们分享下如何查看表空间的使用情况. 一.如何查看使用状况 我们废话不说,先直接贴上 ...

  2. C#剪切生成高质量缩放图片

    /// <summary> /// 高质量缩放图片 /// </summary> /// <param name="OriginFilePath"&g ...

  3. webpack publicpath path

    一.publicpath 用绝对路径:如 /assets/ 会在支援路径前 加上 /assets/ devServer  publicpath 如果没有设置的话,取 publicpath 所以 一般要 ...

  4. tensorflow中一个矩阵和一个向量相加

    import tensorflow as tf x=tf.constant([[1,2],[3,4]]) y=tf.constant([[1],[1]])#列向量 z=tf.constant([1,1 ...

  5. Kotlin函数中默认参数

    Java不支持默认参数.但kotlin函数却可以 package loaderman.demo class Customer(var name:String ="name"){// ...

  6. RecoderUtils录音工具类

    import android.media.MediaRecorder; import android.os.Environment; import java.io.File; import java. ...

  7. 权限控制(delphi actionlist)

    权限控制(delphi TActionList方案)在软件开发中,为软件加入权限控制功能,使不同的用户有不同的使用权限,是非常重要的一项功能,由其在开发数据库方面的应用,这项功能更为重要.但是,要为一 ...

  8. 1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

    在数据库执行脚本文件时,执行到一半会遇到  这种问题: 出错处:2018-05-14 18:53:38 行号:712454 错误代码: 1293 - Incorrect table definitio ...

  9. springboot-springmvc

    0依赖 <!-- jsp --> <dependency> <groupId>org.apache.tomcat.embed</groupId> < ...

  10. 【Hadoop】MapReduce自定义分区Partition输出各运营商的手机号码

    MapReduce和自定义Partition MobileDriver主类 package Partition; import org.apache.hadoop.io.NullWritable; i ...