Table of Contents

Constructor Mat

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Mat()

Creates empty Mat

public Mat()

Mat(Mat)

Initializes by Mat object. The Mat's element type must match TElem.

public Mat(Mat mat)

Parameters

mat Mat

Managed Mat object

Mat(int, int)

constructs 2D matrix of the specified size and type

public Mat(int rows, int cols)

Parameters

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

Mat(Size)

constructs 2D matrix of the specified size and type

public Mat(Size size)

Parameters

size Size

2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.

Mat(int, int, Scalar)

constructs 2D matrix and fills it with the specified Scalar value.

public Mat(int rows, int cols, Scalar s)

Parameters

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

s Scalar

An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .

Mat(Size, Scalar)

constructs 2D matrix and fills it with the specified Scalar value.

public Mat(Size size, Scalar s)

Parameters

size Size

2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.

s Scalar

An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .

Mat(Mat<TElem>, Range, Range?)

creates a matrix header for a part of the bigger matrix

public Mat(Mat<TElem> m, Range rowRange, Range? colRange = null)

Parameters

m Mat<TElem>

Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat::clone() .

rowRange Range

Range of the m rows to take. As usual, the range start is inclusive and the range end is exclusive. Use Range.All to take all the rows.

colRange Range?

Range of the m columns to take. Use Range.All to take all the columns.

Mat(Mat<TElem>, Range[])

creates a matrix header for a part of the bigger matrix

protected Mat(Mat<TElem> m, Range[] ranges)

Parameters

m Mat<TElem>

Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat.Clone() .

ranges Range[]

Array of selected ranges of m along each dimensionality.

Mat(Mat<TElem>, Rect)

creates a matrix header for a part of the bigger matrix

public Mat(Mat<TElem> m, Rect roi)

Parameters

m Mat<TElem>

Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat.Clone() .

roi Rect

Region of interest.

Mat(int, int, Array, long)

constructor for matrix headers pointing to user-allocated data

protected Mat(int rows, int cols, Array data, long step = 0)

Parameters

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

data Array

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically de-allocated, so you should take care of it.

step long

Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .

Mat(IEnumerable<int>, Array, IEnumerable<long>?)

constructor for matrix headers pointing to user-allocated data

public Mat(IEnumerable<int> sizes, Array data, IEnumerable<long>? steps = null)

Parameters

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

data Array

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically de-allocated, so you should take care of it.

steps IEnumerable<long>

Array of ndims-1 steps in case of a multi-dimensional array (the last step is always set to the element size). If not specified, the matrix is assumed to be continuous.

Mat(IEnumerable<int>)

constructs n-dimensional matrix

public Mat(IEnumerable<int> sizes)

Parameters

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

Mat(IEnumerable<int>, Scalar)

constructs n-dimensional matrix

public Mat(IEnumerable<int> sizes, Scalar s)

Parameters

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

s Scalar

An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .