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:
- If the current array shape and the type match the new ones, return immediately. Otherwise, de-reference the previous data by calling Mat::release().
- Initialize the new header.
- Allocate the new data of total()*elemSize() bytes.
- 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:
you can simply write:
because cvtColor , as well as the most of OpenCV functions, calls Mat::create() for the output array internally.