Table of Contents

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

m Mat

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

m Mat

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, params Range[])

creates a matrix header for a part of the bigger matrix

public Mat(Mat m, params Range[] ranges)

Parameters

m Mat

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, Rect)

creates a matrix header for a part of the bigger matrix

public Mat(Mat m, Rect roi)

Parameters

m Mat

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(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

shape MatShape

Matrix shape.

type MatType

Array type.

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

shape MatShape

Matrix shape.

type MatType

Array type.

s Scalar

Value to initialize each element with.

Mat(Size, MatType)

constructs 2D matrix of the specified size and type

public Mat(Size size, MatType type)

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.

type MatType

Array 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

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.

type MatType

Array 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.

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(IEnumerable<int>, MatType)

constructs n-dimensional matrix

public Mat(IEnumerable<int> sizes, MatType type)

Parameters

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

type MatType

Array 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

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

type MatType

Array 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.

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(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

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

type MatType

Array 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.

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(int, int, MatType)

constructs 2D matrix of the specified size and type

public Mat(int rows, int cols, MatType type)

Parameters

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

type MatType

Array 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

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

type MatType

Array 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.

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(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

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

type MatType

Array 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.

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(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

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

type MatType

Array 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.

data nint

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(string, ImreadModes)

Loads an image from a file. (cv::imread)

public Mat(string fileName, ImreadModes flags = ImreadModes.Color)

Parameters

fileName string

Name of file to be loaded.

flags ImreadModes

Specifies color type of the loaded image

Fields

TypeMap

typeof(T) -> MatType

protected static readonly IReadOnlyDictionary<Type, MatType> TypeMap

Field Value

IReadOnlyDictionary<Type, MatType>

Properties

Cols

the number of columns or -1 when the array has more than 2 dimensions

public int Cols { get; }

Property Value

int

Data

pointer to the data

public nint Data { get; }

Property Value

nint

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

nint

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

nint

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

nint

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

int

Flags

includes several bit-fields:

  • the magic signature
  • continuity flag
  • depth
  • number of channels
public int Flags { get; }

Property Value

int

Height

the number of rows or -1 when the array has more than 2 dimensions

public int Height { get; }

Property Value

int

this[Range, Range]

Extracts a rectangular submatrix.

public Mat this[Range rowRange, Range colRange] { get; set; }

Parameters

rowRange Range

Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All().

colRange Range

Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All().

Property Value

Mat

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

ranges Range[]

Array of selected ranges along each array dimension.

Property Value

Mat

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

roi Rect

Extracted submatrix specified as a rectangle.

Property Value

Mat

this[int, int, int, int]

Extracts a rectangular submatrix.

public Mat this[int rowStart, int rowEnd, int colStart, int colEnd] { get; set; }

Parameters

rowStart int

Start row of the extracted submatrix. The upper boundary is not included.

rowEnd int

End row of the extracted submatrix. The upper boundary is not included.

colStart int

Start column of the extracted submatrix. The upper boundary is not included.

colEnd int

End column of the extracted submatrix. The upper boundary is not included.

Property Value

Mat

this[Range, Range]

Extracts a rectangular submatrix.

public Mat this[Range rowRange, Range colRange] { get; set; }

Parameters

rowRange Range

Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All().

colRange Range

Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All().

Property Value

Mat

Rows

the number of rows or -1 when the array has more than 2 dimensions

public int Rows { get; }

Property Value

int

Width

the number of columns or -1 when the array has more than 2 dimensions

public int Width { get; }

Property Value

int

Methods

Add(Mat)

public MatExpr Add(Mat m)

Parameters

m Mat

Returns

MatExpr

Add(Scalar)

public MatExpr Add(Scalar s)

Parameters

s Scalar

Returns

MatExpr

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

dtop int

Shift of the top submatrix boundary upwards.

dbottom int

Shift of the bottom submatrix boundary downwards.

dleft int

Shift of the left submatrix boundary to the left.

dright int

Shift of the right submatrix boundary to the right.

Returns

Mat

Alignment(int)

public Mat Alignment(int n = 4)

Parameters

n int

Returns

Mat

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

T

Element 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

m Mat

Destination array.

type MatType?

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

i0 int

Index 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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index 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

idx int[]

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

m Mat

Returns

MatExpr

BitwiseAnd(double)

public MatExpr BitwiseAnd(double s)

Parameters

s double

Returns

MatExpr

BitwiseOr(Mat)

public MatExpr BitwiseOr(Mat m)

Parameters

m Mat

Returns

MatExpr

BitwiseOr(double)

public MatExpr BitwiseOr(double s)

Parameters

s double

Returns

MatExpr

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

int

CheckVector(int, int, bool)

public int CheckVector(int elemChannels, int depth = -1, bool requireContinuous = true)

Parameters

elemChannels int

Number 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.

depth int

The depth the matrix should have. Set it to -1 when any depth is fine.

requireContinuous bool

Set 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

Mat

Clone(Rect)

Returns the partial Mat of the specified Mat

public Mat Clone(Rect roi)

Parameters

roi Rect

Returns

Mat

Col(int)

Creates a matrix header for the specified matrix column.

public Mat Col(int x)

Parameters

x int

A 0-based column index.

Returns

Mat

ColRange(Range)

Creates a matrix header for the specified column span.

public Mat ColRange(Range range)

Parameters

range Range

Returns

Mat

ColRange(int, int)

Creates a matrix header for the specified column span.

public Mat ColRange(int startCol, int endCol)

Parameters

startCol int

An inclusive 0-based start index of the column span.

endCol int

An exclusive 0-based ending index of the column span.

Returns

Mat

ColRange(Range)

Creates a matrix header for the specified column span.

public Mat ColRange(Range range)

Parameters

range Range

Returns

Mat

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

m OutputArray

output matrix; if it does not have a proper size or type before the operation, it is reallocated.

rtype MatType

desired 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.

alpha double

optional scale factor.

beta double

optional delta added to the scaled values.

CopyTo(Mat, InputArray)

Copies the matrix to another one.

public void CopyTo(Mat m, InputArray mask = default)

Parameters

m Mat

Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

mask InputArray

Operation 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

m OutputArray

Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

mask InputArray

Operation 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

type MatType

New matrix type.

sizes int[]

Array of integers specifying a new array shape.

Create(Size, MatType)

Allocates new array data if needed.

public void Create(Size size, MatType type)

Parameters

size Size

Alternative new matrix size specification: Size(cols, rows)

type MatType

New matrix type.

Create(int, int, MatType)

Allocates new array data if needed.

public void Create(int rows, int cols, MatType type)

Parameters

rows int

New number of rows.

cols int

New number of columns.

type MatType

New matrix type.

Cross(InputArray)

Computes a cross-product of two 3-element vectors.

public Mat Cross(InputArray m)

Parameters

m InputArray

Another cross-product operand.

Returns

Mat

Depth()

Returns the depth of a matrix element.

public int Depth()

Returns

int

Diag(Mat)

Extracts a diagonal from a matrix, or creates a diagonal matrix.

public static Mat Diag(Mat d)

Parameters

d Mat

One-dimensional matrix that represents the main diagonal.

Returns

Mat

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

d MatDiagType

Single-column matrix that forms a diagonal matrix or index of the diagonal, with the following values:

Returns

Mat

DisposeManaged()

Releases managed resources, including the SafeHandle if present.

protected override void DisposeManaged()

Divide(Mat)

public MatExpr Divide(Mat m)

Parameters

m Mat

Returns

MatExpr

Divide(double)

public MatExpr Divide(double s)

Parameters

s double

Returns

MatExpr

Dot(InputArray)

Computes a dot-product of two vectors.

public double Dot(InputArray m)

Parameters

m InputArray

another dot-product operand.

Returns

double

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

format FormatType

Returns

string

ElemSize()

Returns the matrix element size in bytes.

public int ElemSize()

Returns

int

ElemSize1()

Returns the size of each matrix element channel in bytes.

public int ElemSize1()

Returns

int

Empty()

Returns true if the array has no elements.

public bool Empty()

Returns

bool

EmptyClone()

Makes a Mat that have the same size, depth and channels as this image

public Mat EmptyClone()

Returns

Mat

Equals(Mat)

operator ==

public MatExpr Equals(Mat m)

Parameters

m Mat

Returns

MatExpr

Equals(double)

operator ==

public MatExpr Equals(double d)

Parameters

d double

Returns

MatExpr

Eye(Size, MatType)

Returns an identity matrix of the specified size and type.

public static MatExpr Eye(Size size, MatType type)

Parameters

size Size

Alternative to the matrix size specification Size(cols, rows) .

type MatType

Created matrix type.

Returns

MatExpr

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

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

MatExpr

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

size Size

Alternative to the matrix size specification Size(cols, rows).

type MatType

Created matrix type.

Returns

Mat

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

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

Mat

ForEachAsByte(MatForeachFunctionByte)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsByte(MatForeachFunctionByte operation)

Parameters

operation MatForeachFunctionByte

ForEachAsDouble(MatForeachFunctionDouble)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsDouble(MatForeachFunctionDouble operation)

Parameters

operation MatForeachFunctionDouble

ForEachAsFloat(MatForeachFunctionFloat)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsFloat(MatForeachFunctionFloat operation)

Parameters

operation MatForeachFunctionFloat

ForEachAsInt16(MatForeachFunctionInt16)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsInt16(MatForeachFunctionInt16 operation)

Parameters

operation MatForeachFunctionInt16

ForEachAsInt32(MatForeachFunctionInt32)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsInt32(MatForeachFunctionInt32 operation)

Parameters

operation MatForeachFunctionInt32

ForEachAsVec2b(MatForeachFunctionVec2b)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec2b(MatForeachFunctionVec2b operation)

Parameters

operation MatForeachFunctionVec2b

ForEachAsVec2d(MatForeachFunctionVec2d)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec2d(MatForeachFunctionVec2d operation)

Parameters

operation MatForeachFunctionVec2d

ForEachAsVec2f(MatForeachFunctionVec2f)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec2f(MatForeachFunctionVec2f operation)

Parameters

operation MatForeachFunctionVec2f

ForEachAsVec2i(MatForeachFunctionVec2i)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec2i(MatForeachFunctionVec2i operation)

Parameters

operation MatForeachFunctionVec2i

ForEachAsVec2s(MatForeachFunctionVec2s)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec2s(MatForeachFunctionVec2s operation)

Parameters

operation MatForeachFunctionVec2s

ForEachAsVec3b(MatForeachFunctionVec3b)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec3b(MatForeachFunctionVec3b operation)

Parameters

operation MatForeachFunctionVec3b

ForEachAsVec3d(MatForeachFunctionVec3d)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec3d(MatForeachFunctionVec3d operation)

Parameters

operation MatForeachFunctionVec3d

ForEachAsVec3f(MatForeachFunctionVec3f)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec3f(MatForeachFunctionVec3f operation)

Parameters

operation MatForeachFunctionVec3f

ForEachAsVec3i(MatForeachFunctionVec3i)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec3i(MatForeachFunctionVec3i operation)

Parameters

operation MatForeachFunctionVec3i

ForEachAsVec3s(MatForeachFunctionVec3s)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec3s(MatForeachFunctionVec3s operation)

Parameters

operation MatForeachFunctionVec3s

ForEachAsVec4b(MatForeachFunctionVec4b)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec4b(MatForeachFunctionVec4b operation)

Parameters

operation MatForeachFunctionVec4b

ForEachAsVec4d(MatForeachFunctionVec4d)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec4d(MatForeachFunctionVec4d operation)

Parameters

operation MatForeachFunctionVec4d

ForEachAsVec4f(MatForeachFunctionVec4f)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec4f(MatForeachFunctionVec4f operation)

Parameters

operation MatForeachFunctionVec4f

ForEachAsVec4i(MatForeachFunctionVec4i)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec4i(MatForeachFunctionVec4i operation)

Parameters

operation MatForeachFunctionVec4i

ForEachAsVec4s(MatForeachFunctionVec4s)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec4s(MatForeachFunctionVec4s operation)

Parameters

operation MatForeachFunctionVec4s

ForEachAsVec6b(MatForeachFunctionVec6b)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec6b(MatForeachFunctionVec6b operation)

Parameters

operation MatForeachFunctionVec6b

ForEachAsVec6d(MatForeachFunctionVec6d)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec6d(MatForeachFunctionVec6d operation)

Parameters

operation MatForeachFunctionVec6d

ForEachAsVec6f(MatForeachFunctionVec6f)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec6f(MatForeachFunctionVec6f operation)

Parameters

operation MatForeachFunctionVec6f

ForEachAsVec6i(MatForeachFunctionVec6i)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec6i(MatForeachFunctionVec6i operation)

Parameters

operation MatForeachFunctionVec6i

ForEachAsVec6s(MatForeachFunctionVec6s)

Runs the given functor over all matrix elements in parallel.

public void ForEachAsVec6s(MatForeachFunctionVec6s operation)

Parameters

operation MatForeachFunctionVec6s

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

enumerable IEnumerable<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

arr TElem[,]

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

arr TElem[]

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

imageBytes byte[]
mode ImreadModes

Returns

Mat

FromImageData(ReadOnlySpan<byte>, ImreadModes)

Reads image from the specified buffer in memory.

public static Mat FromImageData(ReadOnlySpan<byte> span, ImreadModes mode = ImreadModes.Color)

Parameters

span ReadOnlySpan<byte>

The input slice of bytes.

mode ImreadModes

The same flags as in imread

Returns

Mat

FromNativePointer(nint)

Creates from native cv::Mat* pointer

public static Mat FromNativePointer(nint ptr)

Parameters

ptr nint

Returns

Mat

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

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

type MatType

Array 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.

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.

Returns

Mat

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

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

type MatType

Array 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.

data nint

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.

Returns

Mat

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

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

type MatType

Array 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.

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() .

Returns

Mat

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

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

type MatType

Array 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.

data nint

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() .

Returns

Mat

FromStream(Stream, ImreadModes)

Creates the Mat instance from System.IO.Stream

public static Mat FromStream(Stream stream, ImreadModes mode)

Parameters

stream Stream
mode ImreadModes

Returns

Mat

GetArray<T>(out T[])

Get the data of this matrix as array

[Pure]
public bool GetArray<T>(out T[] data) where T : unmanaged

Parameters

data T[]

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

Mat.Indexer<T>

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

data T[,]

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

accessFlags AccessFlag
usageFlags UMatUsageFlags

Returns

UMat

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

i0 int

Index 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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index 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

idx int[]

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

m Mat

Returns

MatExpr

GreaterThan(double)

operator >

public MatExpr GreaterThan(double d)

Parameters

d double

Returns

MatExpr

GreaterThanOrEqual(Mat)

operator >=

public MatExpr GreaterThanOrEqual(Mat m)

Parameters

m Mat

Returns

MatExpr

GreaterThanOrEqual(double)

operator >=

public MatExpr GreaterThanOrEqual(double d)

Parameters

d double

Returns

MatExpr

ImDecode(byte[], ImreadModes)

Creates the Mat instance from image data (using cv::decode)

public static Mat ImDecode(byte[] imageBytes, ImreadModes mode = ImreadModes.Color)

Parameters

imageBytes byte[]
mode ImreadModes

Returns

Mat

ImDecode(ReadOnlySpan<byte>, ImreadModes)

Reads image from the specified buffer in memory.

public static Mat ImDecode(ReadOnlySpan<byte> span, ImreadModes mode = ImreadModes.Color)

Parameters

span ReadOnlySpan<byte>

The input slice of bytes.

mode ImreadModes

The same flags as in imread

Returns

Mat

Inv(DecompTypes)

Inverses a matrix.

public MatExpr Inv(DecompTypes method = DecompTypes.LU)

Parameters

method DecompTypes

Matrix inversion method

Returns

MatExpr

IsContinuous()

Reports whether the matrix is continuous or not.

public bool IsContinuous()

Returns

bool

IsSubmatrix()

Returns whether this matrix is a part of other matrix or not.

public bool IsSubmatrix()

Returns

bool

LessThan(Mat)

operator <

public MatExpr LessThan(Mat m)

Parameters

m Mat

Returns

MatExpr

LessThan(double)

operator <

public MatExpr LessThan(double d)

Parameters

d double

Returns

MatExpr

LessThanOrEqual(Mat)

operator <=

public MatExpr LessThanOrEqual(Mat m)

Parameters

m Mat

Returns

MatExpr

LessThanOrEqual(double)

operator <=

public MatExpr LessThanOrEqual(double d)

Parameters

d double

Returns

MatExpr

LocateROI(out Size, out Point)

Locates the matrix header within a parent matrix.

public void LocateROI(out Size wholeSize, out Point ofs)

Parameters

wholeSize Size

Output parameter that contains the size of the whole matrix containing *this as a part.

ofs Point

Output 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

m InputArray
scale double

Returns

MatExpr

Multiply(Mat)

public MatExpr Multiply(Mat m)

Parameters

m Mat

Returns

MatExpr

Multiply(double)

public MatExpr Multiply(double s)

Parameters

s double

Returns

MatExpr

Negate()

public MatExpr Negate()

Returns

MatExpr

NotEquals(Mat)

operator !=

public MatExpr NotEquals(Mat m)

Parameters

m Mat

Returns

MatExpr

NotEquals(double)

operator !=

public MatExpr NotEquals(double d)

Parameters

d double

Returns

MatExpr

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

shape MatShape

Created matrix shape.

type MatType

Created matrix type.

Returns

MatExpr

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

type MatType

Created matrix type.

sizes int[]

Array of integers specifying the array shape.

Returns

MatExpr

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

size Size

Alternative to the matrix size specification Size(cols, rows) .

type MatType

Created matrix type.

Returns

MatExpr

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

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

MatExpr

OnesComplement()

public MatExpr OnesComplement()

Returns

MatExpr

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

size Size

Alternative to the matrix size specification Size(cols, rows).

type MatType

Created matrix type.

Returns

Mat

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

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

Mat

Plus()

public MatExpr Plus()

Returns

MatExpr

PopBack(int)

removes several hyper-planes from bottom of the matrix (Mat.pop_back)

public void PopBack(int nElems = 1)

Parameters

nElems int

Ptr(int)

Returns a pointer to the specified matrix row.

public nint Ptr(int i0)

Parameters

i0 int

Index along the dimension 0

Returns

nint

Ptr(int, int)

Returns a pointer to the specified matrix element.

public nint Ptr(int i0, int i1)

Parameters

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

Returns

nint

Ptr(int, int, int)

Returns a pointer to the specified matrix element.

public nint Ptr(int i0, int i1, int i2)

Parameters

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index along the dimension 2

Returns

nint

Ptr(params int[])

Returns a pointer to the specified matrix element.

public nint Ptr(params int[] idx)

Parameters

idx int[]

Array of Mat::dims indices.

Returns

nint

PushBack(Mat)

Adds elements to the bottom of the matrix. (Mat.push_back)

public void PushBack(Mat m)

Parameters

m Mat

Added line(s)

PushBack(Point)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Point value)

Parameters

value Point

Added element

PushBack(Point2d)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Point2d value)

Parameters

value Point2d

Added element

PushBack(Point2f)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Point2f value)

Parameters

value Point2f

Added element

PushBack(Point3d)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Point3d value)

Parameters

value Point3d

Added element

PushBack(Point3f)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Point3f value)

Parameters

value Point3f

Added element

PushBack(Point3i)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Point3i value)

Parameters

value Point3i

Added element

PushBack(Rect)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Rect value)

Parameters

value Rect

Added element

PushBack(Rect2d)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Rect2d value)

Parameters

value Rect2d

Added element

PushBack(Rect2f)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Rect2f value)

Parameters

value Rect2f

Added element

PushBack(Size)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Size value)

Parameters

value Size

Added element

PushBack(Size2d)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Size2d value)

Parameters

value Size2d

Added element

PushBack(Size2f)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Size2f value)

Parameters

value Size2f

Added element

PushBack(Vec2b)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec2b value)

Parameters

value Vec2b

Added element

PushBack(Vec2d)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec2d value)

Parameters

value Vec2d

Added element

PushBack(Vec2f)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec2f value)

Parameters

value Vec2f

Added element

PushBack(Vec2i)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec2i value)

Parameters

value Vec2i

Added element

PushBack(Vec2s)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec2s value)

Parameters

value Vec2s

Added element

PushBack(Vec2w)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec2w value)

Parameters

value Vec2w

Added element

PushBack(Vec3b)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec3b value)

Parameters

value Vec3b

Added element

PushBack(Vec3d)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec3d value)

Parameters

value Vec3d

Added element

PushBack(Vec3f)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec3f value)

Parameters

value Vec3f

Added element

PushBack(Vec3i)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec3i value)

Parameters

value Vec3i

Added element

PushBack(Vec3s)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec3s value)

Parameters

value Vec3s

Added element

PushBack(Vec3w)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec3w value)

Parameters

value Vec3w

Added element

PushBack(Vec4b)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec4b value)

Parameters

value Vec4b

Added element

PushBack(Vec4d)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec4d value)

Parameters

value Vec4d

Added element

PushBack(Vec4f)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec4f value)

Parameters

value Vec4f

Added element

PushBack(Vec4i)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec4i value)

Parameters

value Vec4i

Added element

PushBack(Vec4s)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec4s value)

Parameters

value Vec4s

Added element

PushBack(Vec4w)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec4w value)

Parameters

value Vec4w

Added element

PushBack(Vec6b)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec6b value)

Parameters

value Vec6b

Added element

PushBack(Vec6d)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec6d value)

Parameters

value Vec6d

Added element

PushBack(Vec6f)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec6f value)

Parameters

value Vec6f

Added element

PushBack(Vec6i)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec6i value)

Parameters

value Vec6i

Added element

PushBack(Vec6s)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec6s value)

Parameters

value Vec6s

Added element

PushBack(Vec6w)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(Vec6w value)

Parameters

value Vec6w

Added element

PushBack(byte)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(byte value)

Parameters

value byte

Added element

PushBack(double)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(double value)

Parameters

value double

Added element

PushBack(short)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(short value)

Parameters

value short

Added element

PushBack(int)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(int value)

Parameters

value int

Added element

PushBack(sbyte)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(sbyte value)

Parameters

value sbyte

Added element

PushBack(float)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(float value)

Parameters

value float

Added element

PushBack(ushort)

Adds elements to the bottom of the matrix. (Mat::push_back)

public void PushBack(ushort value)

Parameters

value ushort

Added 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

sz int

Number 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

sz int

Number 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

cn int

New number of channels. If 0, the number of channels remains the same.

newShape MatShape

New shape.

Returns

Mat

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

cn int

New number of channels. If the parameter is 0, the number of channels remains the same.

rows int

New number of rows. If the parameter is 0, the number of rows remains the same.

Returns

Mat

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

cn int

New number of channels. If the parameter is 0, the number of channels remains the same.

newDims int[]

New number of rows. If the parameter is 0, the number of rows remains the same.

Returns

Mat

Resize(int)

Changes the number of matrix rows.

public void Resize(int sz)

Parameters

sz int

New number of rows.

Resize(int, Scalar)

Changes the number of matrix rows.

public void Resize(int sz, Scalar s)

Parameters

sz int

New number of rows.

s Scalar

Value assigned to the newly added elements.

Row(int)

Creates a matrix header for the specified matrix row.

public Mat Row(int y)

Parameters

y int

A 0-based row index.

Returns

Mat

RowRange(Range)

Creates a matrix header for the specified row span.

public Mat RowRange(Range range)

Parameters

range Range

Returns

Mat

RowRange(int, int)

Creates a matrix header for the specified row span.

public Mat RowRange(int startRow, int endRow)

Parameters

startRow int
endRow int

Returns

Mat

RowRange(Range)

Creates a matrix header for the specified row span.

public Mat RowRange(Range range)

Parameters

range Range

Returns

Mat

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

row int

Zero-based row index.

Returns

Span<T>

A span covering the row-th row.

Type Parameters

T

Element 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

data T[]

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

data T[,]

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

value InputArray
mask Mat

Returns

Mat

SetTo(Scalar, Mat?)

Sets all or some of the array elements to the specified value.

public Mat SetTo(Scalar value, Mat? mask = null)

Parameters

value Scalar
mask Mat

Returns

Mat

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index along the dimension 2

value T

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

value T

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

i0 int

Index along the dimension 0

value T

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

idx int[]

Array of Mat::dims indices.

value T

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

MatShape

Size()

Returns a matrix size.

public Size Size()

Returns

Size

Size(int)

Returns a matrix size.

public int Size(int dim)

Parameters

dim int

Returns

int

Step()

Returns number of bytes each matrix row occupies.

public long Step()

Returns

long

Step(int)

Returns number of bytes each matrix row occupies.

public long Step(int i)

Parameters

i int

Returns

long

Step1(int)

Returns a normalized step.

public long Step1(int i = 0)

Parameters

i int

Returns

long

SubMat(Range, Range)

Extracts a rectangular submatrix.

public Mat SubMat(Range rowRange, Range colRange)

Parameters

rowRange Range

Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range::all().

colRange Range

Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range::all().

Returns

Mat

SubMat(params Range[])

Extracts a rectangular submatrix.

public Mat SubMat(params Range[] ranges)

Parameters

ranges Range[]

Array of selected ranges along each array dimension.

Returns

Mat

SubMat(Rect)

Extracts a rectangular submatrix.

public Mat SubMat(Rect roi)

Parameters

roi Rect

Extracted submatrix specified as a rectangle.

Returns

Mat

SubMat(int, int, int, int)

Extracts a rectangular submatrix.

public Mat SubMat(int rowStart, int rowEnd, int colStart, int colEnd)

Parameters

rowStart int
rowEnd int
colStart int
colEnd int

Returns

Mat

SubMat(Range, Range)

Extracts a rectangular submatrix.

public Mat SubMat(Range rowRange, Range colRange)

Parameters

rowRange Range

Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range::all().

colRange Range

Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range::all().

Returns

Mat

Subtract(Mat)

public MatExpr Subtract(Mat m)

Parameters

m Mat

Returns

MatExpr

Subtract(Scalar)

public MatExpr Subtract(Scalar s)

Parameters

s Scalar

Returns

MatExpr

T()

Transposes a matrix.

public MatExpr T()

Returns

MatExpr

ToBytes(string, params ImageEncodingParam[])

Encodes an image into a memory buffer.

public byte[] ToBytes(string ext = ".png", params ImageEncodingParam[] prms)

Parameters

ext string

Encodes an image into a memory buffer.

prms ImageEncodingParam[]

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

ext string

Encodes an image into a memory buffer.

prms int[]

Format-specific parameters.

Returns

byte[]

ToMemoryStream(string, params ImageEncodingParam[])

Converts Mat to System.IO.MemoryStream

public MemoryStream ToMemoryStream(string ext = ".png", params ImageEncodingParam[] prms)

Parameters

ext string
prms ImageEncodingParam[]

Returns

MemoryStream

ToString()

Returns a string that represents this Mat.

public override string ToString()

Returns

string

Total()

Returns the total number of array elements.

public long Total()

Returns

long

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

startDim int
endDim int

Returns

long

Type()

Returns the type of a matrix element.

public MatType Type()

Returns

MatType

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

stream Stream
ext string
prms ImageEncodingParam[]

Xor(Mat)

public MatExpr Xor(Mat m)

Parameters

m Mat

Returns

MatExpr

Xor(double)

public MatExpr Xor(double s)

Parameters

s double

Returns

MatExpr

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

shape MatShape

Created matrix shape.

type MatType

Created matrix type.

Returns

MatExpr

Zeros(MatType, params int[])

Returns a zero array of the specified size and type.

public static MatExpr Zeros(MatType type, params int[] sizes)

Parameters

type MatType

Created matrix type.

sizes int[]

Returns

MatExpr

Zeros(Size, MatType)

Returns a zero array of the specified size and type.

public static MatExpr Zeros(Size size, MatType type)

Parameters

size Size

Alternative to the matrix size specification Size(cols, rows) .

type MatType

Created matrix type.

Returns

MatExpr

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

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

MatExpr

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

size Size

Alternative to the matrix size specification Size(cols, rows).

type MatType

Created matrix type.

Returns

Mat

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

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

Mat

Operators

operator +(Mat, Mat)

public static MatExpr operator +(Mat a, Mat b)

Parameters

a Mat
b Mat

Returns

MatExpr

operator +(Mat, Scalar)

public static MatExpr operator +(Mat a, Scalar s)

Parameters

a Mat
s Scalar

Returns

MatExpr

operator +(Scalar, Mat)

public static MatExpr operator +(Scalar s, Mat a)

Parameters

s Scalar
a Mat

Returns

MatExpr

operator &(Mat, Mat)

public static MatExpr operator &(Mat a, Mat b)

Parameters

a Mat
b Mat

Returns

MatExpr

operator &(Mat, double)

public static MatExpr operator &(Mat a, double s)

Parameters

a Mat
s double

Returns

MatExpr

operator &(double, Mat)

public static MatExpr operator &(double s, Mat a)

Parameters

s double
a Mat

Returns

MatExpr

operator |(Mat, Mat)

public static MatExpr operator |(Mat a, Mat b)

Parameters

a Mat
b Mat

Returns

MatExpr

operator |(Mat, double)

public static MatExpr operator |(Mat a, double s)

Parameters

a Mat
s double

Returns

MatExpr

operator |(double, Mat)

public static MatExpr operator |(double s, Mat a)

Parameters

s double
a Mat

Returns

MatExpr

operator /(Mat, Mat)

public static MatExpr operator /(Mat a, Mat b)

Parameters

a Mat
b Mat

Returns

MatExpr

operator /(Mat, double)

public static MatExpr operator /(Mat a, double s)

Parameters

a Mat
s double

Returns

MatExpr

operator /(double, Mat)

public static MatExpr operator /(double s, Mat a)

Parameters

s double
a Mat

Returns

MatExpr

operator ^(Mat, Mat)

public static MatExpr operator ^(Mat a, Mat b)

Parameters

a Mat
b Mat

Returns

MatExpr

operator ^(Mat, double)

public static MatExpr operator ^(Mat a, double s)

Parameters

a Mat
s double

Returns

MatExpr

operator ^(double, Mat)

public static MatExpr operator ^(double s, Mat a)

Parameters

s double
a Mat

Returns

MatExpr

operator *(Mat, Mat)

public static MatExpr operator *(Mat a, Mat b)

Parameters

a Mat
b Mat

Returns

MatExpr

operator *(Mat, double)

public static MatExpr operator *(Mat a, double s)

Parameters

a Mat
s double

Returns

MatExpr

operator *(double, Mat)

public static MatExpr operator *(double s, Mat a)

Parameters

s double
a Mat

Returns

MatExpr

operator ~(Mat)

public static MatExpr operator ~(Mat m)

Parameters

m Mat

Returns

MatExpr

operator -(Mat, Mat)

public static MatExpr operator -(Mat a, Mat b)

Parameters

a Mat
b Mat

Returns

MatExpr

operator -(Mat, Scalar)

public static MatExpr operator -(Mat a, Scalar s)

Parameters

a Mat
s Scalar

Returns

MatExpr

operator -(Scalar, Mat)

public static MatExpr operator -(Scalar s, Mat a)

Parameters

s Scalar
a Mat

Returns

MatExpr

operator -(Mat)

public static MatExpr operator -(Mat mat)

Parameters

mat Mat

Returns

MatExpr

operator +(Mat)

public static Mat operator +(Mat mat)

Parameters

mat Mat

Returns

Mat