Table of Contents

Class UMat

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

OpenCV C++ n-dimensional dense array class (cv::Mat)

public class UMat : DisposableCvObject, IDisposable, ICvPtrHolder
Inheritance
UMat
Implements
Inherited Members

Constructors

UMat(Size, MatType, Scalar, UMatUsageFlags)

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

public UMat(Size size, MatType type, Scalar s, UMatUsageFlags usageFlags = UMatUsageFlags.None)

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 .

usageFlags UMatUsageFlags

usage flags for allocator

UMat(Size, MatType, UMatUsageFlags)

constructs 2D matrix of the specified size and type

public UMat(Size size, MatType type, UMatUsageFlags usageFlags = UMatUsageFlags.None)

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.

usageFlags UMatUsageFlags

usage flags for allocator

UMat(UMat)

protected UMat(UMat m)

Parameters

m UMat

UMat(UMat, Range, Range, UMatUsageFlags)

creates a matrix header for a part of the bigger matrix

public UMat(UMat m, Range rowRange, Range colRange, UMatUsageFlags usageFlags = UMatUsageFlags.None)

Parameters

m UMat

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.

usageFlags UMatUsageFlags

usage flags for allocator

UMat(UMat, params Range[])

creates a matrix header for a part of the bigger matrix

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

Parameters

m UMat

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.

UMat(UMat, Rect)

creates a matrix header for a part of the bigger matrix

public UMat(UMat m, Rect roi)

Parameters

m UMat

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.

UMat(UMatUsageFlags)

Creates empty Mat

public UMat(UMatUsageFlags usageFlags = UMatUsageFlags.None)

Parameters

usageFlags UMatUsageFlags

UMat(IEnumerable<int>, MatType)

constructs n-dimensional matrix

public UMat(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.

UMat(IEnumerable<int>, MatType, Scalar)

constructs n-dimensional matrix

public UMat(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 .

UMat(int, int, MatType, Scalar, UMatUsageFlags)

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

public UMat(int rows, int cols, MatType type, Scalar s, UMatUsageFlags usageFlags = UMatUsageFlags.None)

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 .

usageFlags UMatUsageFlags

usage flags for allocator

UMat(int, int, MatType, UMatUsageFlags)

constructs 2D matrix of the specified size and type

public UMat(int rows, int cols, MatType type, UMatUsageFlags usageFlags = UMatUsageFlags.None)

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.

usageFlags UMatUsageFlags

usage flags for allocator

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

Dims

the array dimensionality, >= 2

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

UMat

this[Range[]]

Extracts a rectangular submatrix.

[SuppressMessage("Microsoft.Design", "CA1043: Use integral or string argument for indexers")]
public UMat this[params Range[] ranges] { get; set; }

Parameters

ranges Range[]

Array of selected ranges along each array dimension.

Property Value

UMat

this[Rect]

Extracts a rectangular submatrix.

[SuppressMessage("Microsoft.Design", "CA1043: Use integral or string argument for indexers")]
public UMat this[Rect roi] { get; set; }

Parameters

roi Rect

Extracted submatrix specified as a rectangle.

Property Value

UMat

this[int, int, int, int]

Extracts a rectangular submatrix.

public UMat 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

UMat

this[Range, Range]

Extracts a rectangular submatrix.

public UMat 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

UMat

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

AdjustROI(int, int, int, int)

Adjusts a submatrix size and position within the parent matrix.

public UMat 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

UMat

Alignment(int, UMatUsageFlags)

public UMat Alignment(int n = 4, UMatUsageFlags usageFlags = UMatUsageFlags.None)

Parameters

n int
usageFlags UMatUsageFlags

usage flags for allocator

Returns

UMat

AssignTo(UMat, MatType?)

Provides a functional form of convertTo.

public void AssignTo(UMat m, MatType? type = null)

Parameters

m UMat

Destination array.

type MatType?

Desired destination array depth (or -1 if it should be the same as the source type).

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 UMat Clone()

Returns

UMat

Clone(Rect)

Returns the partial Mat of the specified Mat

public UMat Clone(Rect roi)

Parameters

roi Rect

Returns

UMat

Col(int)

Creates a matrix header for the specified matrix column.

public UMat Col(int x)

Parameters

x int

A 0-based column index.

Returns

UMat

ColRange(Range)

Creates a matrix header for the specified column span.

public UMat ColRange(Range range)

Parameters

range Range

Returns

UMat

ColRange(int, int)

Creates a matrix header for the specified column span.

public UMat 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

UMat

ColRange(Range)

Creates a matrix header for the specified column span.

public UMat ColRange(Range range)

Parameters

range Range

Returns

UMat

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(OutputArray, InputArray?)

Copies the matrix to another one.

public void CopyTo(OutputArray m, InputArray? mask = null)

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.

CopyTo(UMat, InputArray?)

Copies the matrix to another one.

public void CopyTo(UMat m, InputArray? mask = null)

Parameters

m UMat

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.

Depth()

Returns the depth of a matrix element.

public int Depth()

Returns

int

Diag(MatDiagType)

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

public UMat 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

UMat

Diag(UMat)

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

public static UMat Diag(UMat d)

Parameters

d UMat

One-dimensional matrix that represents the main diagonal.

Returns

UMat

DisposeUnmanaged()

releases unmanaged resources

protected override void DisposeUnmanaged()

Dot(InputArray)

Computes a dot-product of two vectors.

public double Dot(InputArray m)

Parameters

m InputArray

another dot-product operand.

Returns

double

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

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

public UMat EmptyClone(UMatUsageFlags usageFlags = UMatUsageFlags.None)

Parameters

usageFlags UMatUsageFlags

Returns

UMat

Eye(Size, MatType)

Returns an identity matrix of the specified size and type.

public static UMat Eye(Size size, MatType type)

Parameters

size Size

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

type MatType

Created matrix type.

Returns

UMat

Eye(int, int, MatType)

Returns an identity matrix of the specified size and type.

public static UMat Eye(int rows, int cols, MatType type)

Parameters

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

UMat

FromNativePointer(nint)

Creates from native cv::UMat* pointer

public static UMat FromNativePointer(nint ptr)

Parameters

ptr nint

Returns

UMat

GetMat(AccessFlag)

Returns the UMat data as a Mat.

public Mat GetMat(AccessFlag accessFlags)

Parameters

accessFlags AccessFlag

AccessFlag determining the mode in which the data is to be acquired

Returns

Mat

Inv(DecompTypes)

Inverses a matrix.

public UMat Inv(DecompTypes method = DecompTypes.LU)

Parameters

method DecompTypes

Matrix inversion method

Returns

UMat

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

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 UMat Mul(InputArray m, double scale = 1)

Parameters

m InputArray
scale double

Returns

UMat

Ones(MatType, params int[])

Returns an array of all 1’s of the specified size and type.

public static UMat Ones(MatType type, params int[] sizes)

Parameters

type MatType

Created matrix type.

sizes int[]

Array of integers specifying the array shape.

Returns

UMat

Ones(Size, MatType)

Returns an array of all 1’s of the specified size and type.

public static UMat Ones(Size size, MatType type)

Parameters

size Size

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

type MatType

Created matrix type.

Returns

UMat

Ones(int, int, MatType)

Returns an array of all 1’s of the specified size and type.

public static UMat Ones(int rows, int cols, MatType type)

Parameters

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

UMat

Release()

Releases the resources

public void Release()

Reshape(int, int)

Changes the shape and/or the number of channels of a 2D matrix without copying the data.

public UMat 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

UMat

Reshape(int, params int[])

Changes the shape and/or the number of channels of a 2D matrix without copying the data.

public UMat 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

UMat

Row(int)

Creates a matrix header for the specified matrix row.

public UMat Row(int y)

Parameters

y int

A 0-based row index.

Returns

UMat

RowRange(Range)

Creates a matrix header for the specified row span.

public UMat RowRange(Range range)

Parameters

range Range

Returns

UMat

RowRange(int, int)

Creates a matrix header for the specified row span.

public UMat RowRange(int startRow, int endRow)

Parameters

startRow int
endRow int

Returns

UMat

RowRange(Range)

Creates a matrix header for the specified row span.

public UMat RowRange(Range range)

Parameters

range Range

Returns

UMat

SetTo(InputArray, UMat?)

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

public UMat SetTo(InputArray value, UMat? mask = null)

Parameters

value InputArray
mask UMat

Returns

UMat

SetTo(Scalar, UMat?)

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

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

Parameters

value Scalar
mask UMat

Returns

UMat

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

UMat

SubMat(params Range[])

Extracts a rectangular submatrix.

public UMat SubMat(params Range[] ranges)

Parameters

ranges Range[]

Array of selected ranges along each array dimension.

Returns

UMat

SubMat(Rect)

Extracts a rectangular submatrix.

public UMat SubMat(Rect roi)

Parameters

roi Rect

Extracted submatrix specified as a rectangle.

Returns

UMat

SubMat(int, int, int, int)

Extracts a rectangular submatrix.

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

Parameters

rowStart int
rowEnd int
colStart int
colEnd int

Returns

UMat

SubMat(Range, Range)

Extracts a rectangular submatrix.

public UMat 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

UMat

T()

Transposes a matrix.

public UMat T()

Returns

UMat

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

Type()

Returns the type of a matrix element.

public MatType Type()

Returns

MatType

Zeros(MatType, params int[])

Returns a zero array of the specified size and type.

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

Parameters

type MatType

Created matrix type.

sizes int[]

Returns

UMat

Zeros(Size, MatType)

Returns a zero array of the specified size and type.

public static UMat Zeros(Size size, MatType type)

Parameters

size Size

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

type MatType

Created matrix type.

Returns

UMat

Zeros(int, int, MatType)

Returns a zero array of the specified size and type.

public static UMat Zeros(int rows, int cols, MatType type)

Parameters

rows int

Number of rows.

cols int

Number of columns.

type MatType

Created matrix type.

Returns

UMat