Mat::create

Mat::create

Allocates new array data if needed.

C++:  void  Mat:: create (int  rows, int  cols, int  type )
C++:  void  Mat:: create (Size  size, int  type )
C++:  void  Mat:: create (int  ndims, const int*  sizes, int  type )
Parameters:
  • ndims – New array dimensionality.
  • rows – New number of rows.
  • cols – New number of columns.
  • size – Alternative new matrix size specification: Size(cols, rows)
  • sizes – Array of integers specifying a new array shape.
  • type – New matrix type.

This is one of the key Mat methods. Most new-style OpenCV functions and methods that produce arrays call this method for each output array. The method uses the following algorithm:

  1. If the current array shape and the type match the new ones, return immediately. Otherwise, de-reference the previous data by calling Mat::release().
  2. Initialize the new header.
  3. Allocate the new data of total()*elemSize() bytes.
  4. Allocate the new, associated with the data, reference counter and set it to 1.

Such a scheme makes the memory management robust and efficient at the same time and helps avoid extra typing for you. This means that usually there is no need to explicitly allocate output arrays. That is, instead of writing:

Mat color;
...
Mat gray(color.rows, color.cols, color.depth());
cvtColor(color, gray, CV_BGR2GRAY);

you can simply write:

Mat color;
...
Mat gray;
cvtColor(color, gray, CV_BGR2GRAY);

because cvtColor , as well as the most of OpenCV functions, calls Mat::create() for the output array internally.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值