Class Mat
- Namespace
- OpenCvSharp
- Assembly
- OpenCvSharp.dll
OpenCV C++ n-dimensional dense array class (cv::Mat)
public class Mat : CvObject, IDisposable
- Inheritance
-
Mat
- Implements
- Derived
-
Mat<TElem>
- Inherited Members
- Extension Methods
Constructors
Mat()
Creates empty Mat
public Mat()
Mat(Mat)
protected Mat(Mat m)
Parameters
mMat
Mat(Mat, Range, Range?)
creates a matrix header for a part of the bigger matrix
public Mat(Mat m, Range rowRange, Range? colRange = null)
Parameters
mMatArray 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() .
rowRangeRangeRange 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.
colRangeRange?Range of the m columns to take. Use Range.All to take all the columns.
Mat(Mat, params Range[])
creates a matrix header for a part of the bigger matrix
public Mat(Mat m, params Range[] ranges)
Parameters
mMatArray 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() .
rangesRange[]Array of selected ranges of m along each dimensionality.
Mat(Mat, Rect)
creates a matrix header for a part of the bigger matrix
public Mat(Mat m, Rect roi)
Parameters
mMatArray 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() .
roiRectRegion of interest.
Mat(MatShape, MatType)
Constructs a matrix of the given shape (OpenCV 5). The shape may be N-D, a 0-D scalar or empty, and can carry a data layout and channel count.
public Mat(MatShape shape, MatType type)
Parameters
Mat(MatShape, MatType, Scalar)
Constructs a matrix of the given shape (OpenCV 5), initialized with the given value.
public Mat(MatShape shape, MatType type, Scalar s)
Parameters
shapeMatShapeMatrix shape.
typeMatTypeArray type.
sScalarValue to initialize each element with.
Mat(Size, MatType)
constructs 2D matrix of the specified size and type
public Mat(Size size, MatType type)
Parameters
sizeSize2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType.CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
Mat(Size, MatType, Scalar)
constructs 2D matrix and fills it with the specified Scalar value.
public Mat(Size size, MatType type, Scalar s)
Parameters
sizeSize2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
sScalarAn 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(IEnumerable<int>, MatType)
constructs n-dimensional matrix
public Mat(IEnumerable<int> sizes, MatType type)
Parameters
sizesIEnumerable<int>Array of integers specifying an n-dimensional array shape.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
Mat(IEnumerable<int>, MatType, Scalar)
constructs n-dimensional matrix
public Mat(IEnumerable<int> sizes, MatType type, Scalar s)
Parameters
sizesIEnumerable<int>Array of integers specifying an n-dimensional array shape.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
sScalarAn 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(IEnumerable<int>, MatType, Array, IEnumerable<long>?)
constructor for matrix headers pointing to user-allocated data
protected Mat(IEnumerable<int> sizes, MatType type, Array data, IEnumerable<long>? steps = null)
Parameters
sizesIEnumerable<int>Array of integers specifying an n-dimensional array shape.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
dataArrayPointer 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.
stepsIEnumerable<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(int, int, MatType)
constructs 2D matrix of the specified size and type
public Mat(int rows, int cols, MatType type)
Parameters
rowsintNumber of rows in a 2D array.
colsintNumber of columns in a 2D array.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
Mat(int, int, MatType, Scalar)
constructs 2D matrix and fills it with the specified Scalar value.
public Mat(int rows, int cols, MatType type, Scalar s)
Parameters
rowsintNumber of rows in a 2D array.
colsintNumber of columns in a 2D array.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
sScalarAn 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(int, int, MatType, Array, long)
Constructor for matrix headers pointing to user-allocated data.
Do not use this constructor directly. Please use FromPixelData(int, int, MatType, nint, long) instead.
This constructor was removed from the public API because the introduction of nint in .NET caused overload resolution confusion.
protected Mat(int rows, int cols, MatType type, Array data, long step = 0)
Parameters
rowsintNumber of rows in a 2D array.
colsintNumber of columns in a 2D array.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
dataArrayPointer 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.
steplongNumber 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(int, int, MatType, nint, long)
constructor for matrix headers pointing to user-allocated data
[Obsolete("Use Mat.FromPixelData instead. This constructor has been deprecated because the introduction of 'nint' made overload resolution confusing.", true)]
public Mat(int rows, int cols, MatType type, nint data, long step = 0)
Parameters
rowsintNumber of rows in a 2D array.
colsintNumber of columns in a 2D array.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
datanintPointer 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.
steplongNumber 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(string, ImreadModes)
Loads an image from a file. (cv::imread)
public Mat(string fileName, ImreadModes flags = ImreadModes.Color)
Parameters
fileNamestringName of file to be loaded.
flagsImreadModesSpecifies color type of the loaded image
Fields
TypeMap
typeof(T) -> MatType
protected static readonly IReadOnlyDictionary<Type, MatType> TypeMap
Field Value
Properties
Cols
the number of columns or -1 when the array has more than 2 dimensions
public int Cols { get; }
Property Value
Data
pointer to the data
public nint Data { get; }
Property Value
DataEnd
The pointer that is possible to compute a relative sub-array position in the main container array using locateROI()
public nint DataEnd { get; }
Property Value
DataLimit
The pointer that is possible to compute a relative sub-array position in the main container array using locateROI()
public nint DataLimit { get; }
Property Value
DataPointer
unsafe pointer to the data
public byte* DataPointer { get; }
Property Value
- byte*
DataStart
The pointer that is possible to compute a relative sub-array position in the main container array using locateROI()
public nint DataStart { get; }
Property Value
Dims
The array dimensionality. In OpenCV 5 this can also be 0 (a scalar; rows == cols == total() == 1) or 1 (a 1D array; dims == rows == 1, cols == total() == N); use Empty() to tell an empty matrix apart from a 0D scalar.
public int Dims { get; }
Property Value
Flags
includes several bit-fields:
- the magic signature
- continuity flag
- depth
- number of channels
public int Flags { get; }
Property Value
Height
the number of rows or -1 when the array has more than 2 dimensions
public int Height { get; }
Property Value
this[Range, Range]
Extracts a rectangular submatrix.
public Mat this[Range rowRange, Range colRange] { get; set; }
Parameters
rowRangeRangeStart and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All().
colRangeRangeStart and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All().
Property Value
this[Range[]]
Extracts a rectangular submatrix.
[SuppressMessage("Microsoft.Design", "CA1043: Use integral or string argument for indexers")]
public Mat this[params Range[] ranges] { get; set; }
Parameters
rangesRange[]Array of selected ranges along each array dimension.
Property Value
this[Rect]
Extracts a rectangular submatrix.
[SuppressMessage("Microsoft.Design", "CA1043: Use integral or string argument for indexers")]
public Mat this[Rect roi] { get; set; }
Parameters
roiRectExtracted submatrix specified as a rectangle.
Property Value
this[int, int, int, int]
Extracts a rectangular submatrix.
public Mat this[int rowStart, int rowEnd, int colStart, int colEnd] { get; set; }
Parameters
rowStartintStart row of the extracted submatrix. The upper boundary is not included.
rowEndintEnd row of the extracted submatrix. The upper boundary is not included.
colStartintStart column of the extracted submatrix. The upper boundary is not included.
colEndintEnd column of the extracted submatrix. The upper boundary is not included.
Property Value
this[Range, Range]
Extracts a rectangular submatrix.
public Mat this[Range rowRange, Range colRange] { get; set; }
Parameters
rowRangeRangeStart and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All().
colRangeRangeStart and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All().
Property Value
Rows
the number of rows or -1 when the array has more than 2 dimensions
public int Rows { get; }
Property Value
Width
the number of columns or -1 when the array has more than 2 dimensions
public int Width { get; }
Property Value
Methods
Add(Mat)
public MatExpr Add(Mat m)
Parameters
mMat
Returns
Add(Scalar)
public MatExpr Add(Scalar s)
Parameters
sScalar
Returns
AdjustROI(int, int, int, int)
Adjusts a submatrix size and position within the parent matrix.
public Mat AdjustROI(int dtop, int dbottom, int dleft, int dright)
Parameters
dtopintShift of the top submatrix boundary upwards.
dbottomintShift of the bottom submatrix boundary downwards.
dleftintShift of the left submatrix boundary to the left.
drightintShift of the right submatrix boundary to the right.
Returns
Alignment(int)
public Mat Alignment(int n = 4)
Parameters
nint
Returns
AsRows<T>()
Returns a MatRowAccessor<T> that provides efficient row-by-row access with no P/Invoke per row or per element. The data pointer, step, and dimensions are captured once; all indexing is pure pointer arithmetic.
public MatRowAccessor<T> AsRows<T>() where T : unmanaged
Returns
- MatRowAccessor<T>
A MatRowAccessor<T> over this matrix.
Type Parameters
TElement type. Must match the matrix element type (e.g. Vec3b for CV_8UC3).
Remarks
Parallel usage: Because MatRowAccessor<T> is a ref struct it cannot be
captured by a lambda closure. Call this method inside each Parallel.For iteration to obtain
a per-thread local accessor:
Parallel.For(0, mat.Rows, y =>
{
Span<float> row = mat.AsRows<float>()[y];
for (int x = 0; x < row.Length; x++)
row[x] = ComputeValue(y, x);
});
Exceptions
- InvalidOperationException
Thrown when the matrix is not 2-dimensional.
AsSpan<T>()
Creates a new span over the Mat. The matrix must be continuous (IsContinuous()); returns an empty span otherwise.
public Span<T> AsSpan<T>() where T : unmanaged
Returns
- Span<T>
Type Parameters
T
AssignTo(Mat, MatType?)
Provides a functional form of convertTo.
public void AssignTo(Mat m, MatType? type = null)
Parameters
mMatDestination array.
typeMatType?Desired destination array depth (or -1 if it should be the same as the source type).
At<T>(int)
Returns a reference to the specified array element.
For 2D matrices, i0 is the row index (dimension 0).
Do NOT call this with a column index on a row-submatrix obtained from Row(int);
use At<T>(int, int) or RowSpan<T>(int) instead.
For performance-sensitive pixel loops, prefer AsRows<T>().
public ref T At<T>(int i0) where T : unmanaged
Parameters
i0intIndex along the dimension 0
Returns
- T
A reference to the specified array element.
Type Parameters
T
At<T>(int, int)
Returns a value to the specified array element.
public ref T At<T>(int i0, int i1) where T : unmanaged
Parameters
Returns
- T
A value to the specified array element.
Type Parameters
T
At<T>(int, int, int)
Returns a value to the specified array element.
public ref T At<T>(int i0, int i1, int i2) where T : unmanaged
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
Returns
- T
A value to the specified array element.
Type Parameters
T
At<T>(params int[])
Returns a value to the specified array element.
public ref T At<T>(params int[] idx) where T : unmanaged
Parameters
idxint[]Array of Mat::dims indices.
Returns
- T
A value to the specified array element.
Type Parameters
T
BitwiseAnd(Mat)
public MatExpr BitwiseAnd(Mat m)
Parameters
mMat
Returns
BitwiseAnd(double)
public MatExpr BitwiseAnd(double s)
Parameters
sdouble
Returns
BitwiseOr(Mat)
public MatExpr BitwiseOr(Mat m)
Parameters
mMat
Returns
BitwiseOr(double)
public MatExpr BitwiseOr(double s)
Parameters
sdouble
Returns
Cast<TMat>()
Creates type-specific Mat instance from this.
public TMat Cast<TMat>() where TMat : Mat
Returns
- TMat
Type Parameters
TMat
Channels()
Returns the number of matrix channels.
public int Channels()
Returns
CheckVector(int, int, bool)
public int CheckVector(int elemChannels, int depth = -1, bool requireContinuous = true)
Parameters
elemChannelsintNumber of channels or number of columns the matrix should have. For a 2-D matrix, when the matrix has only 1 column, then it should have elemChannels channels; When the matrix has only 1 channel, then it should have elemChannels columns. For a 3-D matrix, it should have only one channel. Furthermore, if the number of planes is not one, then the number of rows within every plane has to be 1; if the number of rows within every plane is not 1, then the number of planes has to be 1.
depthintThe depth the matrix should have. Set it to -1 when any depth is fine.
requireContinuousboolSet it to true to require the matrix to be continuous
Returns
- int
-1 if the requirement is not satisfied. Otherwise, it returns the number of elements in the matrix. Note that an element may have multiple channels.
Clone()
Creates a full copy of the matrix.
public Mat Clone()
Returns
Clone(Rect)
Returns the partial Mat of the specified Mat
public Mat Clone(Rect roi)
Parameters
roiRect
Returns
Col(int)
Creates a matrix header for the specified matrix column.
public Mat Col(int x)
Parameters
xintA 0-based column index.
Returns
ColRange(Range)
Creates a matrix header for the specified column span.
public Mat ColRange(Range range)
Parameters
rangeRange
Returns
ColRange(int, int)
Creates a matrix header for the specified column span.
public Mat ColRange(int startCol, int endCol)
Parameters
startColintAn inclusive 0-based start index of the column span.
endColintAn exclusive 0-based ending index of the column span.
Returns
ColRange(Range)
Creates a matrix header for the specified column span.
public Mat ColRange(Range range)
Parameters
rangeRange
Returns
ConvertTo(OutputArray, MatType, double, double)
Converts an array to another data type with optional scaling.
public void ConvertTo(OutputArray m, MatType rtype, double alpha = 1, double beta = 0)
Parameters
mOutputArrayoutput matrix; if it does not have a proper size or type before the operation, it is reallocated.
rtypeMatTypedesired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.
alphadoubleoptional scale factor.
betadoubleoptional delta added to the scaled values.
CopyTo(Mat, InputArray)
Copies the matrix to another one.
public void CopyTo(Mat m, InputArray mask = default)
Parameters
mMatDestination matrix. If it does not have a proper size or type before the operation, it is reallocated.
maskInputArrayOperation mask. Its non-zero elements indicate which matrix elements need to be copied.
CopyTo(OutputArray, InputArray)
Copies the matrix to another one.
public void CopyTo(OutputArray m, InputArray mask = default)
Parameters
mOutputArrayDestination matrix. If it does not have a proper size or type before the operation, it is reallocated.
maskInputArrayOperation mask. Its non-zero elements indicate which matrix elements need to be copied.
Create(MatType, params int[])
Allocates new array data if needed.
public void Create(MatType type, params int[] sizes)
Parameters
Create(Size, MatType)
Allocates new array data if needed.
public void Create(Size size, MatType type)
Parameters
Create(int, int, MatType)
Allocates new array data if needed.
public void Create(int rows, int cols, MatType type)
Parameters
Cross(InputArray)
Computes a cross-product of two 3-element vectors.
public Mat Cross(InputArray m)
Parameters
mInputArrayAnother cross-product operand.
Returns
Depth()
Returns the depth of a matrix element.
public int Depth()
Returns
Diag(Mat)
Extracts a diagonal from a matrix, or creates a diagonal matrix.
public static Mat Diag(Mat d)
Parameters
dMatOne-dimensional matrix that represents the main diagonal.
Returns
Diag(MatDiagType)
Single-column matrix that forms a diagonal matrix or index of the diagonal, with the following values:
public Mat Diag(MatDiagType d = MatDiagType.Main)
Parameters
dMatDiagTypeSingle-column matrix that forms a diagonal matrix or index of the diagonal, with the following values:
Returns
DisposeManaged()
Releases managed resources, including the SafeHandle if present.
protected override void DisposeManaged()
Divide(Mat)
public MatExpr Divide(Mat m)
Parameters
mMat
Returns
Divide(double)
public MatExpr Divide(double s)
Parameters
sdouble
Returns
Dot(InputArray)
Computes a dot-product of two vectors.
public double Dot(InputArray m)
Parameters
mInputArrayanother dot-product operand.
Returns
Dump(FormatType)
Returns a string that represents each element value of Mat. This method corresponds to std::ostream << Mat
public string Dump(FormatType format = FormatType.Default)
Parameters
formatFormatType
Returns
ElemSize()
Returns the matrix element size in bytes.
public int ElemSize()
Returns
ElemSize1()
Returns the size of each matrix element channel in bytes.
public int ElemSize1()
Returns
Empty()
Returns true if the array has no elements.
public bool Empty()
Returns
EmptyClone()
Makes a Mat that have the same size, depth and channels as this image
public Mat EmptyClone()
Returns
Equals(Mat)
operator ==
public MatExpr Equals(Mat m)
Parameters
mMat
Returns
Equals(double)
operator ==
public MatExpr Equals(double d)
Parameters
ddouble
Returns
Eye(Size, MatType)
Returns an identity matrix of the specified size and type.
public static MatExpr Eye(Size size, MatType type)
Parameters
sizeSizeAlternative to the matrix size specification Size(cols, rows) .
typeMatTypeCreated matrix type.
Returns
Eye(int, int, MatType)
Returns an identity matrix of the specified size and type.
public static MatExpr Eye(int rows, int cols, MatType type)
Parameters
Returns
EyeMat(Size, MatType)
Returns an identity matrix of the specified size and type as Mat.
Unlike Eye(Size, MatType), this method returns a Mat directly,
so a single using statement is sufficient to manage its lifetime.
public static Mat EyeMat(Size size, MatType type)
Parameters
sizeSizeAlternative to the matrix size specification Size(cols, rows).
typeMatTypeCreated matrix type.
Returns
EyeMat(int, int, MatType)
Returns an identity matrix of the specified size and type as Mat.
Unlike Eye(int, int, MatType), this method returns a Mat directly,
so a single using statement is sufficient to manage its lifetime.
public static Mat EyeMat(int rows, int cols, MatType type)
Parameters
Returns
ForEachAsByte(MatForeachFunctionByte)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsByte(MatForeachFunctionByte operation)
Parameters
operationMatForeachFunctionByte
ForEachAsDouble(MatForeachFunctionDouble)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsDouble(MatForeachFunctionDouble operation)
Parameters
operationMatForeachFunctionDouble
ForEachAsFloat(MatForeachFunctionFloat)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsFloat(MatForeachFunctionFloat operation)
Parameters
operationMatForeachFunctionFloat
ForEachAsInt16(MatForeachFunctionInt16)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsInt16(MatForeachFunctionInt16 operation)
Parameters
operationMatForeachFunctionInt16
ForEachAsInt32(MatForeachFunctionInt32)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsInt32(MatForeachFunctionInt32 operation)
Parameters
operationMatForeachFunctionInt32
ForEachAsVec2b(MatForeachFunctionVec2b)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec2b(MatForeachFunctionVec2b operation)
Parameters
operationMatForeachFunctionVec2b
ForEachAsVec2d(MatForeachFunctionVec2d)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec2d(MatForeachFunctionVec2d operation)
Parameters
operationMatForeachFunctionVec2d
ForEachAsVec2f(MatForeachFunctionVec2f)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec2f(MatForeachFunctionVec2f operation)
Parameters
operationMatForeachFunctionVec2f
ForEachAsVec2i(MatForeachFunctionVec2i)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec2i(MatForeachFunctionVec2i operation)
Parameters
operationMatForeachFunctionVec2i
ForEachAsVec2s(MatForeachFunctionVec2s)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec2s(MatForeachFunctionVec2s operation)
Parameters
operationMatForeachFunctionVec2s
ForEachAsVec3b(MatForeachFunctionVec3b)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec3b(MatForeachFunctionVec3b operation)
Parameters
operationMatForeachFunctionVec3b
ForEachAsVec3d(MatForeachFunctionVec3d)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec3d(MatForeachFunctionVec3d operation)
Parameters
operationMatForeachFunctionVec3d
ForEachAsVec3f(MatForeachFunctionVec3f)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec3f(MatForeachFunctionVec3f operation)
Parameters
operationMatForeachFunctionVec3f
ForEachAsVec3i(MatForeachFunctionVec3i)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec3i(MatForeachFunctionVec3i operation)
Parameters
operationMatForeachFunctionVec3i
ForEachAsVec3s(MatForeachFunctionVec3s)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec3s(MatForeachFunctionVec3s operation)
Parameters
operationMatForeachFunctionVec3s
ForEachAsVec4b(MatForeachFunctionVec4b)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec4b(MatForeachFunctionVec4b operation)
Parameters
operationMatForeachFunctionVec4b
ForEachAsVec4d(MatForeachFunctionVec4d)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec4d(MatForeachFunctionVec4d operation)
Parameters
operationMatForeachFunctionVec4d
ForEachAsVec4f(MatForeachFunctionVec4f)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec4f(MatForeachFunctionVec4f operation)
Parameters
operationMatForeachFunctionVec4f
ForEachAsVec4i(MatForeachFunctionVec4i)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec4i(MatForeachFunctionVec4i operation)
Parameters
operationMatForeachFunctionVec4i
ForEachAsVec4s(MatForeachFunctionVec4s)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec4s(MatForeachFunctionVec4s operation)
Parameters
operationMatForeachFunctionVec4s
ForEachAsVec6b(MatForeachFunctionVec6b)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec6b(MatForeachFunctionVec6b operation)
Parameters
operationMatForeachFunctionVec6b
ForEachAsVec6d(MatForeachFunctionVec6d)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec6d(MatForeachFunctionVec6d operation)
Parameters
operationMatForeachFunctionVec6d
ForEachAsVec6f(MatForeachFunctionVec6f)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec6f(MatForeachFunctionVec6f operation)
Parameters
operationMatForeachFunctionVec6f
ForEachAsVec6i(MatForeachFunctionVec6i)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec6i(MatForeachFunctionVec6i operation)
Parameters
operationMatForeachFunctionVec6i
ForEachAsVec6s(MatForeachFunctionVec6s)
Runs the given functor over all matrix elements in parallel.
public void ForEachAsVec6s(MatForeachFunctionVec6s operation)
Parameters
operationMatForeachFunctionVec6s
FromArray<TElem>(IEnumerable<TElem>)
Initializes as N x 1 matrix and copies array data to this
public static Mat<TElem> FromArray<TElem>(IEnumerable<TElem> enumerable) where TElem : unmanaged
Parameters
enumerableIEnumerable<TElem>Source array data to be copied to this
Returns
- Mat<TElem>
Type Parameters
TElem
FromArray<TElem>(TElem[,])
Initializes as M x N matrix and copies array data to this
public static Mat<TElem> FromArray<TElem>(TElem[,] arr) where TElem : unmanaged
Parameters
arrTElem[,]Source array data to be copied to this
Returns
- Mat<TElem>
Type Parameters
TElem
FromArray<TElem>(params TElem[])
Initializes as N x 1 matrix and copies array data to this
public static Mat<TElem> FromArray<TElem>(params TElem[] arr) where TElem : unmanaged
Parameters
arrTElem[]Source array data to be copied to this
Returns
- Mat<TElem>
Type Parameters
TElem
FromImageData(byte[], ImreadModes)
Creates the Mat instance from image data (using cv::decode)
public static Mat FromImageData(byte[] imageBytes, ImreadModes mode = ImreadModes.Color)
Parameters
imageBytesbyte[]modeImreadModes
Returns
FromImageData(ReadOnlySpan<byte>, ImreadModes)
Reads image from the specified buffer in memory.
public static Mat FromImageData(ReadOnlySpan<byte> span, ImreadModes mode = ImreadModes.Color)
Parameters
spanReadOnlySpan<byte>The input slice of bytes.
modeImreadModesThe same flags as in imread
Returns
FromNativePointer(nint)
Creates from native cv::Mat* pointer
public static Mat FromNativePointer(nint ptr)
Parameters
ptrnint
Returns
FromPixelData(IEnumerable<int>, MatType, Array, IEnumerable<long>?)
constructor for matrix headers pointing to user-allocated data
public static Mat FromPixelData(IEnumerable<int> sizes, MatType type, Array data, IEnumerable<long>? steps = null)
Parameters
sizesIEnumerable<int>Array of integers specifying an n-dimensional array shape.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
dataArrayPointer 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.
stepsIEnumerable<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.
Returns
FromPixelData(IEnumerable<int>, MatType, nint, IEnumerable<long>?)
constructor for matrix headers pointing to user-allocated data
public static Mat FromPixelData(IEnumerable<int> sizes, MatType type, nint data, IEnumerable<long>? steps = null)
Parameters
sizesIEnumerable<int>Array of integers specifying an n-dimensional array shape.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
datanintPointer 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.
stepsIEnumerable<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.
Returns
FromPixelData(int, int, MatType, Array, long)
Constructor for matrix headers pointing to user-allocated data.
public static Mat FromPixelData(int rows, int cols, MatType type, Array data, long step = 0)
Parameters
rowsintNumber of rows in a 2D array.
colsintNumber of columns in a 2D array.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
dataArrayPointer 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.
steplongNumber 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
FromPixelData(int, int, MatType, nint, long)
constructor for matrix headers pointing to user-allocated data
public static Mat FromPixelData(int rows, int cols, MatType type, nint data, long step = 0)
Parameters
rowsintNumber of rows in a 2D array.
colsintNumber of columns in a 2D array.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
datanintPointer 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.
steplongNumber 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
FromStream(Stream, ImreadModes)
Creates the Mat instance from System.IO.Stream
public static Mat FromStream(Stream stream, ImreadModes mode)
Parameters
streamStreammodeImreadModes
Returns
GetArray<T>(out T[])
Get the data of this matrix as array
[Pure]
public bool GetArray<T>(out T[] data) where T : unmanaged
Parameters
dataT[]Primitive or Vec array to be copied
Returns
- bool
Length of copied bytes
Type Parameters
T
Examples
using var m1 = new Mat(1, 1, MatType.CV_8UC1); m1.GetArray(out byte[] array);
using var m2 = new Mat(1, 1, MatType.CV_32SC1); m2.GetArray(out int[] array);
using var m3 = new Mat(1, 1, MatType.CV_8UC(6)); m3.GetArray(out Vec6b[] array);
using var m4 = new Mat(1, 1, MatType.CV_64FC4); m4.GetArray(out Vec4d[] array);
GetGenericIndexer<T>()
Gets a type-specific indexer. The indexer has getters/setters to access each matrix element.
[Obsolete("Use At<T>(row, col) for occasional access, or AsRows<T>() for high-performance loops. GetGenericIndexer uses Marshal.PtrToStructure which is slower than both alternatives.")]
public Mat.Indexer<T> GetGenericIndexer<T>() where T : struct
Returns
Type Parameters
T
GetRectangularArray<T>(out T[,])
Get the data of this matrix as array
[Pure]
public bool GetRectangularArray<T>(out T[,] data) where T : unmanaged
Parameters
dataT[,]Primitive or Vec array to be copied
Returns
- bool
Length of copied bytes
Type Parameters
T
Examples
using var m1 = new Mat(1, 1, MatType.CV_8UC1); m1.GetRectangularArray(out byte[,] array);
using var m2 = new Mat(1, 1, MatType.CV_32SC1); m2.GetRectangularArray(out int[,] array);
using var m3 = new Mat(1, 1, MatType.CV_8UC(6)); m3.GetRectangularArray(out Vec6b[,] array);
using var m4 = new Mat(1, 1, MatType.CV_64FC4); m4.GetRectangularArray(out Vec4d[,] array);
GetUMat(AccessFlag, UMatUsageFlags)
Retrieve UMat from Mat
public UMat GetUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags)
Parameters
accessFlagsAccessFlagusageFlagsUMatUsageFlags
Returns
GetUnsafeGenericIndexer<T>()
Gets a type-specific unsafe indexer. The indexer has getters/setters to access each matrix element.
public Mat.UnsafeIndexer<T> GetUnsafeGenericIndexer<T>() where T : unmanaged
Returns
- Mat.UnsafeIndexer<T>
Type Parameters
T
Get<T>(int)
Returns a value to the specified array element.
public T Get<T>(int i0) where T : struct
Parameters
i0intIndex along the dimension 0
Returns
- T
A value to the specified array element.
Type Parameters
T
Get<T>(int, int)
Returns a value to the specified array element.
public T Get<T>(int i0, int i1) where T : struct
Parameters
Returns
- T
A value to the specified array element.
Type Parameters
T
Get<T>(int, int, int)
Returns a value to the specified array element.
public T Get<T>(int i0, int i1, int i2) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
Returns
- T
A value to the specified array element.
Type Parameters
T
Get<T>(params int[])
Returns a value to the specified array element.
public T Get<T>(params int[] idx) where T : struct
Parameters
idxint[]Array of Mat::dims indices.
Returns
- T
A value to the specified array element.
Type Parameters
T
GreaterThan(Mat)
operator >
public MatExpr GreaterThan(Mat m)
Parameters
mMat
Returns
GreaterThan(double)
operator >
public MatExpr GreaterThan(double d)
Parameters
ddouble
Returns
GreaterThanOrEqual(Mat)
operator >=
public MatExpr GreaterThanOrEqual(Mat m)
Parameters
mMat
Returns
GreaterThanOrEqual(double)
operator >=
public MatExpr GreaterThanOrEqual(double d)
Parameters
ddouble
Returns
ImDecode(byte[], ImreadModes)
Creates the Mat instance from image data (using cv::decode)
public static Mat ImDecode(byte[] imageBytes, ImreadModes mode = ImreadModes.Color)
Parameters
imageBytesbyte[]modeImreadModes
Returns
ImDecode(ReadOnlySpan<byte>, ImreadModes)
Reads image from the specified buffer in memory.
public static Mat ImDecode(ReadOnlySpan<byte> span, ImreadModes mode = ImreadModes.Color)
Parameters
spanReadOnlySpan<byte>The input slice of bytes.
modeImreadModesThe same flags as in imread
Returns
Inv(DecompTypes)
Inverses a matrix.
public MatExpr Inv(DecompTypes method = DecompTypes.LU)
Parameters
methodDecompTypesMatrix inversion method
Returns
IsContinuous()
Reports whether the matrix is continuous or not.
public bool IsContinuous()
Returns
IsSubmatrix()
Returns whether this matrix is a part of other matrix or not.
public bool IsSubmatrix()
Returns
LessThan(Mat)
operator <
public MatExpr LessThan(Mat m)
Parameters
mMat
Returns
LessThan(double)
operator <
public MatExpr LessThan(double d)
Parameters
ddouble
Returns
LessThanOrEqual(Mat)
operator <=
public MatExpr LessThanOrEqual(Mat m)
Parameters
mMat
Returns
LessThanOrEqual(double)
operator <=
public MatExpr LessThanOrEqual(double d)
Parameters
ddouble
Returns
LocateROI(out Size, out Point)
Locates the matrix header within a parent matrix.
public void LocateROI(out Size wholeSize, out Point ofs)
Parameters
wholeSizeSizeOutput parameter that contains the size of the whole matrix containing *this as a part.
ofsPointOutput parameter that contains an offset of *this inside the whole matrix.
Mul(InputArray, double)
Performs an element-wise multiplication or division of the two matrices.
public MatExpr Mul(InputArray m, double scale = 1)
Parameters
mInputArrayscaledouble
Returns
Multiply(Mat)
public MatExpr Multiply(Mat m)
Parameters
mMat
Returns
Multiply(double)
public MatExpr Multiply(double s)
Parameters
sdouble
Returns
Negate()
public MatExpr Negate()
Returns
NotEquals(Mat)
operator !=
public MatExpr NotEquals(Mat m)
Parameters
mMat
Returns
NotEquals(double)
operator !=
public MatExpr NotEquals(double d)
Parameters
ddouble
Returns
Ones(MatShape, MatType)
Returns an array of all 1's of the specified shape and type (OpenCV 5, MatShape).
public static MatExpr Ones(MatShape shape, MatType type)
Parameters
Returns
Ones(MatType, params int[])
Returns an array of all 1’s of the specified size and type.
public static MatExpr Ones(MatType type, params int[] sizes)
Parameters
Returns
Ones(Size, MatType)
Returns an array of all 1’s of the specified size and type.
public static MatExpr Ones(Size size, MatType type)
Parameters
sizeSizeAlternative to the matrix size specification Size(cols, rows) .
typeMatTypeCreated matrix type.
Returns
Ones(int, int, MatType)
Returns an array of all 1’s of the specified size and type.
public static MatExpr Ones(int rows, int cols, MatType type)
Parameters
Returns
OnesComplement()
public MatExpr OnesComplement()
Returns
OnesMat(Size, MatType)
Returns an array of all 1's of the specified size and type as Mat.
Unlike Ones(Size, MatType), this method returns a Mat directly,
so a single using statement is sufficient to manage its lifetime.
public static Mat OnesMat(Size size, MatType type)
Parameters
sizeSizeAlternative to the matrix size specification Size(cols, rows).
typeMatTypeCreated matrix type.
Returns
OnesMat(int, int, MatType)
Returns an array of all 1's of the specified size and type as Mat.
Unlike Ones(int, int, MatType), this method returns a Mat directly,
so a single using statement is sufficient to manage its lifetime.
public static Mat OnesMat(int rows, int cols, MatType type)
Parameters
Returns
Plus()
public MatExpr Plus()
Returns
PopBack(int)
removes several hyper-planes from bottom of the matrix (Mat.pop_back)
public void PopBack(int nElems = 1)
Parameters
nElemsint
Ptr(int)
Returns a pointer to the specified matrix row.
public nint Ptr(int i0)
Parameters
i0intIndex along the dimension 0
Returns
Ptr(int, int)
Returns a pointer to the specified matrix element.
public nint Ptr(int i0, int i1)
Parameters
Returns
Ptr(int, int, int)
Returns a pointer to the specified matrix element.
public nint Ptr(int i0, int i1, int i2)
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
Returns
Ptr(params int[])
Returns a pointer to the specified matrix element.
public nint Ptr(params int[] idx)
Parameters
idxint[]Array of Mat::dims indices.
Returns
PushBack(Mat)
Adds elements to the bottom of the matrix. (Mat.push_back)
public void PushBack(Mat m)
Parameters
mMatAdded line(s)
PushBack(Point)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Point value)
Parameters
valuePointAdded element
PushBack(Point2d)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Point2d value)
Parameters
valuePoint2dAdded element
PushBack(Point2f)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Point2f value)
Parameters
valuePoint2fAdded element
PushBack(Point3d)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Point3d value)
Parameters
valuePoint3dAdded element
PushBack(Point3f)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Point3f value)
Parameters
valuePoint3fAdded element
PushBack(Point3i)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Point3i value)
Parameters
valuePoint3iAdded element
PushBack(Rect)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Rect value)
Parameters
valueRectAdded element
PushBack(Rect2d)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Rect2d value)
Parameters
valueRect2dAdded element
PushBack(Rect2f)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Rect2f value)
Parameters
valueRect2fAdded element
PushBack(Size)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Size value)
Parameters
valueSizeAdded element
PushBack(Size2d)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Size2d value)
Parameters
valueSize2dAdded element
PushBack(Size2f)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Size2f value)
Parameters
valueSize2fAdded element
PushBack(Vec2b)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec2b value)
Parameters
valueVec2bAdded element
PushBack(Vec2d)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec2d value)
Parameters
valueVec2dAdded element
PushBack(Vec2f)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec2f value)
Parameters
valueVec2fAdded element
PushBack(Vec2i)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec2i value)
Parameters
valueVec2iAdded element
PushBack(Vec2s)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec2s value)
Parameters
valueVec2sAdded element
PushBack(Vec2w)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec2w value)
Parameters
valueVec2wAdded element
PushBack(Vec3b)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec3b value)
Parameters
valueVec3bAdded element
PushBack(Vec3d)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec3d value)
Parameters
valueVec3dAdded element
PushBack(Vec3f)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec3f value)
Parameters
valueVec3fAdded element
PushBack(Vec3i)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec3i value)
Parameters
valueVec3iAdded element
PushBack(Vec3s)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec3s value)
Parameters
valueVec3sAdded element
PushBack(Vec3w)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec3w value)
Parameters
valueVec3wAdded element
PushBack(Vec4b)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec4b value)
Parameters
valueVec4bAdded element
PushBack(Vec4d)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec4d value)
Parameters
valueVec4dAdded element
PushBack(Vec4f)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec4f value)
Parameters
valueVec4fAdded element
PushBack(Vec4i)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec4i value)
Parameters
valueVec4iAdded element
PushBack(Vec4s)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec4s value)
Parameters
valueVec4sAdded element
PushBack(Vec4w)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec4w value)
Parameters
valueVec4wAdded element
PushBack(Vec6b)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec6b value)
Parameters
valueVec6bAdded element
PushBack(Vec6d)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec6d value)
Parameters
valueVec6dAdded element
PushBack(Vec6f)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec6f value)
Parameters
valueVec6fAdded element
PushBack(Vec6i)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec6i value)
Parameters
valueVec6iAdded element
PushBack(Vec6s)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec6s value)
Parameters
valueVec6sAdded element
PushBack(Vec6w)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(Vec6w value)
Parameters
valueVec6wAdded element
PushBack(byte)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(byte value)
Parameters
valuebyteAdded element
PushBack(double)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(double value)
Parameters
valuedoubleAdded element
PushBack(short)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(short value)
Parameters
valueshortAdded element
PushBack(int)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(int value)
Parameters
valueintAdded element
PushBack(sbyte)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(sbyte value)
Parameters
valuesbyteAdded element
PushBack(float)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(float value)
Parameters
valuefloatAdded element
PushBack(ushort)
Adds elements to the bottom of the matrix. (Mat::push_back)
public void PushBack(ushort value)
Parameters
valueushortAdded element
Release()
Releases the resources
public void Release()
Reserve(int)
Reserves space for the certain number of rows.
The method reserves space for sz rows. If the matrix already has enough space to store sz rows, nothing happens. If the matrix is reallocated, the first Mat::rows rows are preserved. The method emulates the corresponding method of the STL vector class.
public void Reserve(int sz)
Parameters
szintNumber of rows.
ReserveBuffer(int)
Reserves space for the certain number of bytes.
The method reserves space for sz bytes. If the matrix already has enough space to store sz bytes, nothing happens. If matrix has to be reallocated its previous content could be lost.
public void ReserveBuffer(int sz)
Parameters
szintNumber of bytes.
Reshape(int, MatShape)
Changes the shape (and optionally the number of channels) of the matrix without copying the data, using a MatShape (OpenCV 5).
public Mat Reshape(int cn, MatShape newShape)
Parameters
cnintNew number of channels. If 0, the number of channels remains the same.
newShapeMatShapeNew shape.
Returns
Reshape(int, int)
Changes the shape and/or the number of channels of a 2D matrix without copying the data.
public Mat Reshape(int cn, int rows = 0)
Parameters
cnintNew number of channels. If the parameter is 0, the number of channels remains the same.
rowsintNew number of rows. If the parameter is 0, the number of rows remains the same.
Returns
Reshape(int, params int[])
Changes the shape and/or the number of channels of a 2D matrix without copying the data.
public Mat Reshape(int cn, params int[] newDims)
Parameters
cnintNew number of channels. If the parameter is 0, the number of channels remains the same.
newDimsint[]New number of rows. If the parameter is 0, the number of rows remains the same.
Returns
Resize(int)
Changes the number of matrix rows.
public void Resize(int sz)
Parameters
szintNew number of rows.
Resize(int, Scalar)
Changes the number of matrix rows.
public void Resize(int sz, Scalar s)
Parameters
Row(int)
Creates a matrix header for the specified matrix row.
public Mat Row(int y)
Parameters
yintA 0-based row index.
Returns
RowRange(Range)
Creates a matrix header for the specified row span.
public Mat RowRange(Range range)
Parameters
rangeRange
Returns
RowRange(int, int)
Creates a matrix header for the specified row span.
public Mat RowRange(int startRow, int endRow)
Parameters
Returns
RowRange(Range)
Creates a matrix header for the specified row span.
public Mat RowRange(Range range)
Parameters
rangeRange
Returns
RowSpan<T>(int)
Returns a Span<T> over a single row of this matrix without allocating a submatrix object. Padding bytes between rows are excluded from the span. For iterating all rows in a loop, prefer AsRows<T>() which captures the step once.
public Span<T> RowSpan<T>(int row) where T : unmanaged
Parameters
rowintZero-based row index.
Returns
- Span<T>
A span covering the
row-th row.
Type Parameters
TElement type. Must match the matrix element type.
SetArray<T>(params T[])
Set the specified array data to this matrix
public bool SetArray<T>(params T[] data) where T : unmanaged
Parameters
dataT[]Primitive or Vec array to be copied
Returns
- bool
Length of copied bytes
Type Parameters
T
SetRectangularArray<T>(T[,])
Set the specified array data to this matrix
public bool SetRectangularArray<T>(T[,] data) where T : unmanaged
Parameters
dataT[,]Primitive or Vec array to be copied
Returns
- bool
Length of copied bytes
Type Parameters
T
SetTo(InputArray, Mat?)
Sets all or some of the array elements to the specified value.
public Mat SetTo(InputArray value, Mat? mask = null)
Parameters
valueInputArraymaskMat
Returns
SetTo(Scalar, Mat?)
Sets all or some of the array elements to the specified value.
public Mat SetTo(Scalar value, Mat? mask = null)
Parameters
Returns
Set<T>(int, int, int, T)
Set a value to the specified array element.
public void Set<T>(int i0, int i1, int i2, T value) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
valueT
Type Parameters
T
Set<T>(int, int, T)
Set a value to the specified array element.
public void Set<T>(int i0, int i1, T value) where T : struct
Parameters
Type Parameters
T
Set<T>(int, T)
Set a value to the specified array element.
public void Set<T>(int i0, T value) where T : struct
Parameters
i0intIndex along the dimension 0
valueT
Type Parameters
T
Set<T>(int[], T)
Set a value to the specified array element.
public void Set<T>(int[] idx, T value) where T : struct
Parameters
idxint[]Array of Mat::dims indices.
valueT
Type Parameters
T
Shape()
Returns the shape of the matrix as a MatShape (OpenCV 5), including its data layout and channel count, and distinguishing an empty matrix from a 0-D scalar.
public MatShape Shape()
Returns
Size()
Returns a matrix size.
public Size Size()
Returns
Size(int)
Returns a matrix size.
public int Size(int dim)
Parameters
dimint
Returns
Step()
Returns number of bytes each matrix row occupies.
public long Step()
Returns
Step(int)
Returns number of bytes each matrix row occupies.
public long Step(int i)
Parameters
iint
Returns
Step1(int)
Returns a normalized step.
public long Step1(int i = 0)
Parameters
iint
Returns
SubMat(Range, Range)
Extracts a rectangular submatrix.
public Mat SubMat(Range rowRange, Range colRange)
Parameters
rowRangeRangeStart and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range::all().
colRangeRangeStart and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range::all().
Returns
SubMat(params Range[])
Extracts a rectangular submatrix.
public Mat SubMat(params Range[] ranges)
Parameters
rangesRange[]Array of selected ranges along each array dimension.
Returns
SubMat(Rect)
Extracts a rectangular submatrix.
public Mat SubMat(Rect roi)
Parameters
roiRectExtracted submatrix specified as a rectangle.
Returns
SubMat(int, int, int, int)
Extracts a rectangular submatrix.
public Mat SubMat(int rowStart, int rowEnd, int colStart, int colEnd)
Parameters
Returns
SubMat(Range, Range)
Extracts a rectangular submatrix.
public Mat SubMat(Range rowRange, Range colRange)
Parameters
rowRangeRangeStart and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range::all().
colRangeRangeStart and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range::all().
Returns
Subtract(Mat)
public MatExpr Subtract(Mat m)
Parameters
mMat
Returns
Subtract(Scalar)
public MatExpr Subtract(Scalar s)
Parameters
sScalar
Returns
T()
Transposes a matrix.
public MatExpr T()
Returns
ToBytes(string, params ImageEncodingParam[])
Encodes an image into a memory buffer.
public byte[] ToBytes(string ext = ".png", params ImageEncodingParam[] prms)
Parameters
extstringEncodes an image into a memory buffer.
prmsImageEncodingParam[]Format-specific parameters.
Returns
- byte[]
ToBytes(string, int[]?)
Encodes an image into a memory buffer.
public byte[] ToBytes(string ext = ".png", int[]? prms = null)
Parameters
Returns
- byte[]
ToMemoryStream(string, params ImageEncodingParam[])
Converts Mat to System.IO.MemoryStream
public MemoryStream ToMemoryStream(string ext = ".png", params ImageEncodingParam[] prms)
Parameters
extstringprmsImageEncodingParam[]
Returns
ToString()
Returns a string that represents this Mat.
public override string ToString()
Returns
Total()
Returns the total number of array elements.
public long Total()
Returns
Total(int, int)
Returns the total number of array elements. The method returns the number of elements within a certain sub-array slice with startDim <= dim < endDim
public long Total(int startDim, int endDim = 2147483647)
Parameters
Returns
Type()
Returns the type of a matrix element.
public MatType Type()
Returns
WriteToStream(Stream, string, params ImageEncodingParam[])
Writes image data encoded from this Mat to System.IO.Stream
public void WriteToStream(Stream stream, string ext = ".png", params ImageEncodingParam[] prms)
Parameters
streamStreamextstringprmsImageEncodingParam[]
Xor(Mat)
public MatExpr Xor(Mat m)
Parameters
mMat
Returns
Xor(double)
public MatExpr Xor(double s)
Parameters
sdouble
Returns
Zeros(MatShape, MatType)
Returns a zero array of the specified shape and type (OpenCV 5, MatShape).
public static MatExpr Zeros(MatShape shape, MatType type)
Parameters
Returns
Zeros(MatType, params int[])
Returns a zero array of the specified size and type.
public static MatExpr Zeros(MatType type, params int[] sizes)
Parameters
Returns
Zeros(Size, MatType)
Returns a zero array of the specified size and type.
public static MatExpr Zeros(Size size, MatType type)
Parameters
sizeSizeAlternative to the matrix size specification Size(cols, rows) .
typeMatTypeCreated matrix type.
Returns
Zeros(int, int, MatType)
Returns a zero array of the specified size and type.
public static MatExpr Zeros(int rows, int cols, MatType type)
Parameters
Returns
ZerosMat(Size, MatType)
Returns a zero array of the specified size and type as Mat.
Unlike Zeros(Size, MatType), this method returns a Mat directly,
so a single using statement is sufficient to manage its lifetime.
public static Mat ZerosMat(Size size, MatType type)
Parameters
sizeSizeAlternative to the matrix size specification Size(cols, rows).
typeMatTypeCreated matrix type.
Returns
ZerosMat(int, int, MatType)
Returns a zero array of the specified size and type as Mat.
Unlike Zeros(int, int, MatType), this method returns a Mat directly,
so a single using statement is sufficient to manage its lifetime.
public static Mat ZerosMat(int rows, int cols, MatType type)
Parameters
Returns
Operators
operator +(Mat, Mat)
public static MatExpr operator +(Mat a, Mat b)
Parameters
Returns
operator +(Mat, Scalar)
public static MatExpr operator +(Mat a, Scalar s)
Parameters
Returns
operator +(Scalar, Mat)
public static MatExpr operator +(Scalar s, Mat a)
Parameters
Returns
operator &(Mat, Mat)
public static MatExpr operator &(Mat a, Mat b)
Parameters
Returns
operator &(Mat, double)
public static MatExpr operator &(Mat a, double s)
Parameters
Returns
operator &(double, Mat)
public static MatExpr operator &(double s, Mat a)
Parameters
Returns
operator |(Mat, Mat)
public static MatExpr operator |(Mat a, Mat b)
Parameters
Returns
operator |(Mat, double)
public static MatExpr operator |(Mat a, double s)
Parameters
Returns
operator |(double, Mat)
public static MatExpr operator |(double s, Mat a)
Parameters
Returns
operator /(Mat, Mat)
public static MatExpr operator /(Mat a, Mat b)
Parameters
Returns
operator /(Mat, double)
public static MatExpr operator /(Mat a, double s)
Parameters
Returns
operator /(double, Mat)
public static MatExpr operator /(double s, Mat a)
Parameters
Returns
operator ^(Mat, Mat)
public static MatExpr operator ^(Mat a, Mat b)
Parameters
Returns
operator ^(Mat, double)
public static MatExpr operator ^(Mat a, double s)
Parameters
Returns
operator ^(double, Mat)
public static MatExpr operator ^(double s, Mat a)
Parameters
Returns
operator *(Mat, Mat)
public static MatExpr operator *(Mat a, Mat b)
Parameters
Returns
operator *(Mat, double)
public static MatExpr operator *(Mat a, double s)
Parameters
Returns
operator *(double, Mat)
public static MatExpr operator *(double s, Mat a)
Parameters
Returns
operator ~(Mat)
public static MatExpr operator ~(Mat m)
Parameters
mMat
Returns
operator -(Mat, Mat)
public static MatExpr operator -(Mat a, Mat b)
Parameters
Returns
operator -(Mat, Scalar)
public static MatExpr operator -(Mat a, Scalar s)
Parameters
Returns
operator -(Scalar, Mat)
public static MatExpr operator -(Scalar s, Mat a)
Parameters
Returns
operator -(Mat)
public static MatExpr operator -(Mat mat)
Parameters
matMat
Returns
operator +(Mat)
public static Mat operator +(Mat mat)
Parameters
matMat