Class Mat<TElem>
Type-specific abstract matrix
Implements
Inherited Members
Namespace: OpenCvSharp
Assembly: OpenCvSharp.dll
Syntax
public class Mat<TElem> : Mat, ICvPtrHolder where TElem : struct
Type Parameters
Name | Description |
---|---|
TElem | Element Type |
Constructors
| Improve this Doc View SourceMat()
Creates empty Mat
Declaration
public Mat()
Mat(IEnumerable<Int32>)
constructs n-dimensional matrix
Declaration
public Mat(IEnumerable<int> sizes)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.Int32> | sizes | Array of integers specifying an n-dimensional array shape. |
Mat(IEnumerable<Int32>, Array, Nullable<IEnumerable<Int64>>)
constructor for matrix headers pointing to user-allocated data
Declaration
public Mat(IEnumerable<int> sizes, Array data, IEnumerable<long>? steps = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.Int32> | sizes | Array of integers specifying an n-dimensional array shape. |
Array | data | 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. |
System.Nullable<IEnumerable<System.Int64>> | steps | 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<Int32>, Scalar)
constructs n-dimensional matrix
Declaration
public Mat(IEnumerable<int> sizes, Scalar s)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.Int32> | sizes | Array of integers specifying an n-dimensional array shape. |
OpenCvSharp.Scalar | s | 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)
Initializes by Mat object
Declaration
public Mat(Mat mat)
Parameters
Type | Name | Description |
---|---|---|
Mat | mat | Managed Mat object |
Mat(Mat<TElem>, Range, Nullable<Range>)
creates a matrix header for a part of the bigger matrix
Declaration
public Mat(Mat<TElem> m, Range rowRange, Range? colRange = null)
Parameters
Type | Name | Description |
---|---|---|
Mat<TElem> | m | 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() . |
OpenCvSharp.Range | rowRange | 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. |
System.Nullable<OpenCvSharp.Range> | colRange | 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
Declaration
protected Mat(Mat<TElem> m, params Range[] ranges)
Parameters
Type | Name | Description |
---|---|---|
Mat<TElem> | m | 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() . |
OpenCvSharp.Range[] | ranges | Array of selected ranges of m along each dimensionality. |
Mat(Mat<TElem>, Rect)
creates a matrix header for a part of the bigger matrix
Declaration
public Mat(Mat<TElem> m, Rect roi)
Parameters
Type | Name | Description |
---|---|---|
Mat<TElem> | m | 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() . |
OpenCvSharp.Rect | roi | Region of interest. |
Mat(Size)
constructs 2D matrix of the specified size and type
Declaration
public Mat(Size size)
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.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(Size, Scalar)
constructs 2D matrix and fills it with the specified Scalar value.
Declaration
public Mat(Size size, Scalar s)
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.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. |
OpenCvSharp.Scalar | s | 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(Int32, Int32)
constructs 2D matrix of the specified size and type
Declaration
public Mat(int rows, int cols)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rows | Number of rows in a 2D array. |
System.Int32 | cols | Number of columns in a 2D array. |
Mat(Int32, Int32, Array, Int64)
constructor for matrix headers pointing to user-allocated data
Declaration
protected Mat(int rows, int cols, Array data, long step = 0L)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rows | Number of rows in a 2D array. |
System.Int32 | cols | Number of columns in a 2D array. |
Array | data | 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. |
System.Int64 | step | 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(Int32, Int32, Scalar)
constructs 2D matrix and fills it with the specified Scalar value.
Declaration
public Mat(int rows, int cols, Scalar s)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rows | Number of rows in a 2D array. |
System.Int32 | cols | Number of columns in a 2D array. |
OpenCvSharp.Scalar | s | 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 . |
Properties
| Improve this Doc View SourceItem[Range, Range]
Extracts a rectangular submatrix.
Declaration
public Mat<TElem> this[Range rowRange, Range colRange] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.Range | rowRange | Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All(). |
OpenCvSharp.Range | colRange | Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All(). |
Property Value
Type | Description |
---|---|
Mat<TElem> |
Item[Range[]]
Extracts a rectangular submatrix.
Declaration
public Mat<TElem> this[params Range[] ranges] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.Range[] | ranges | Array of selected ranges along each array dimension. |
Property Value
Type | Description |
---|---|
Mat<TElem> |
Item[Rect]
Extracts a rectangular submatrix.
Declaration
public Mat<TElem> this[Rect roi] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.Rect | roi | Extracted submatrix specified as a rectangle. |
Property Value
Type | Description |
---|---|
Mat<TElem> |
Item[Int32, Int32, Int32, Int32]
Extracts a rectangular submatrix.
Declaration
public Mat<TElem> this[int rowStart, int rowEnd, int colStart, int colEnd] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowStart | Start row of the extracted submatrix. The upper boundary is not included. |
System.Int32 | rowEnd | End row of the extracted submatrix. The upper boundary is not included. |
System.Int32 | colStart | Start column of the extracted submatrix. The upper boundary is not included. |
System.Int32 | colEnd | End column of the extracted submatrix. The upper boundary is not included. |
Property Value
Type | Description |
---|---|
Mat<TElem> |
Methods
| Improve this Doc View SourceClone()
Creates a full copy of the matrix.
Declaration
public Mat<TElem> Clone()
Returns
Type | Description |
---|---|
Mat<TElem> |
FromNativePointer(IntPtr)
Creates from native cv::Mat* pointer
Declaration
public static Mat<TElem> FromNativePointer(IntPtr ptr)
Parameters
Type | Name | Description |
---|---|---|
IntPtr | ptr |
Returns
Type | Description |
---|---|
Mat<TElem> |
FromPixelData(IEnumerable<Int32>, IntPtr, Nullable<IEnumerable<Int64>>)
constructor for matrix headers pointing to user-allocated data
Declaration
public static Mat<TElem> FromPixelData(IEnumerable<int> sizes, IntPtr data, IEnumerable<long>? steps = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.Int32> | sizes | Array of integers specifying an n-dimensional array shape. |
IntPtr | data | 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. |
System.Nullable<IEnumerable<System.Int64>> | steps | 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. |
Returns
Type | Description |
---|---|
Mat<TElem> |
FromPixelData(Int32, Int32, Array, Int64)
constructor for matrix headers pointing to user-allocated data
Declaration
public static Mat<TElem> FromPixelData(int rows, int cols, Array data, long step = 0L)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rows | Number of rows in a 2D array. |
System.Int32 | cols | Number of columns in a 2D array. |
Array | data | 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. |
System.Int64 | step | 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() . |
Returns
Type | Description |
---|---|
Mat<TElem> |
FromPixelData(Int32, Int32, IntPtr, Int64)
constructor for matrix headers pointing to user-allocated data
Declaration
public static Mat<TElem> FromPixelData(int rows, int cols, IntPtr data, long step = 0L)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rows | Number of rows in a 2D array. |
System.Int32 | cols | Number of columns in a 2D array. |
IntPtr | data | 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. |
System.Int64 | step | 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() . |
Returns
Type | Description |
---|---|
Mat<TElem> |
GetEnumerator()
Gets read-only enumerator
Declaration
public IEnumerator<TElem> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<TElem> |
GetIndexer()
Gets a type-specific indexer. The indexer has getters/setters to access each matrix element.
Declaration
public MatIndexer<TElem> GetIndexer()
Returns
Type | Description |
---|---|
MatIndexer<TElem> |
Reshape(Int32)
Changes the shape of channels of a 2D matrix without copying the data.
Declaration
public Mat<TElem> Reshape(int rows)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rows | New number of rows. If the parameter is 0, the number of rows remains the same. |
Returns
Type | Description |
---|---|
Mat<TElem> |
Reshape(Int32[])
Changes the shape of a 2D matrix without copying the data.
Declaration
public Mat<TElem> Reshape(params int[] newDims)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | newDims | New number of rows. If the parameter is 0, the number of rows remains the same. |
Returns
Type | Description |
---|---|
Mat<TElem> |
SubMat(Range, Range)
Extracts a rectangular submatrix.
Declaration
public Mat<TElem> SubMat(Range rowRange, Range colRange)
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.Range | rowRange | Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All(). |
OpenCvSharp.Range | colRange | Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All(). |
Returns
Type | Description |
---|---|
Mat<TElem> |
SubMat(Range[])
Extracts a rectangular submatrix.
Declaration
public Mat<TElem> SubMat(params Range[] ranges)
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.Range[] | ranges | Array of selected ranges along each array dimension. |
Returns
Type | Description |
---|---|
Mat<TElem> |
SubMat(Rect)
Extracts a rectangular submatrix.
Declaration
public Mat<TElem> SubMat(Rect roi)
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.Rect | roi | Extracted submatrix specified as a rectangle. |
Returns
Type | Description |
---|---|
Mat<TElem> |
SubMat(Int32, Int32, Int32, Int32)
Extracts a rectangular submatrix.
Declaration
public Mat<TElem> SubMat(int rowStart, int rowEnd, int colStart, int colEnd)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowStart | Start row of the extracted submatrix. The upper boundary is not included. |
System.Int32 | rowEnd | End row of the extracted submatrix. The upper boundary is not included. |
System.Int32 | colStart | Start column of the extracted submatrix. The upper boundary is not included. |
System.Int32 | colEnd | End column of the extracted submatrix. The upper boundary is not included. |
Returns
Type | Description |
---|---|
Mat<TElem> |
T()
Transposes a matrix.
Declaration
public Mat<TElem> T()
Returns
Type | Description |
---|---|
Mat<TElem> |
ToArray()
Convert this mat to managed array
Declaration
public TElem[] ToArray()
Returns
Type | Description |
---|---|
TElem[] |
ToRectangularArray()
Convert this mat to managed rectangular array
Declaration
public TElem[, ] ToRectangularArray()
Returns
Type | Description |
---|---|
TElem[,] |
Wrap(Mat)
Declaration
protected Mat<TElem> Wrap(Mat mat)
Parameters
Type | Name | Description |
---|---|---|
Mat | mat |
Returns
Type | Description |
---|---|
Mat<TElem> |