Table of Contents

Class UMat

Namespace
Emgu.CV
Assembly
Emgu.CV.dll

The equivalent of cv::Mat, should only be used if you know what you are doing. In most case you should use the Matrix class instead

[JsonConverter(typeof(UMat.UMatJsonConverter))]
public class UMat : UnmanagedObject, IEquatable<UMat>, IInputOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays, IOutputArray, IInputArray, IDisposable, ISerializable
Inheritance
UMat
Implements
Inherited Members
Extension Methods

Constructors

UMat(UMat, Range, Range)

Create a umat header for the specific ROI

public UMat(UMat umat, Range rowRange, Range colRange)

Parameters

umat UMat

The umat where the new UMat header will share data from

rowRange Range

The region of interest

colRange Range

The region of interest

UMat(UMat, Rectangle)

Get the Umat header for the specific roi of the parent

public UMat(UMat parent, Rectangle roi)

Parameters

parent UMat

The parent Umat

roi Rectangle

The region of interest

UMat(Usage)

Create an empty cv::UMat

public UMat(UMat.Usage usage = Usage.Default)

Parameters

usage UMat.Usage

Allocation Usage

UMat(Size, DepthType, int, Usage)

Create a umat of the specific type.

public UMat(Size size, DepthType type, int channels, UMat.Usage usage = Usage.Default)

Parameters

size Size

Size of the UMat

type DepthType

Mat element type

channels int

Number of channels

usage UMat.Usage

Allocation Usage

UMat(int, int, DepthType, int, Usage)

Create a umat of the specific type.

public UMat(int rows, int cols, DepthType type, int channels, UMat.Usage usage = Usage.Default)

Parameters

rows int

Number of rows in a 2D array.

cols int

Number of columns in a 2D array.

type DepthType

Mat element type

channels int

Number of channels

usage UMat.Usage

Allocation Usage

UMat(SerializationInfo, StreamingContext)

Constructor used to deserialize runtime serialized object

public UMat(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

The serialization info

context StreamingContext

The streaming context

UMat(string, ImreadModes)

Read a UMat from file.

public UMat(string fileName, ImreadModes loadType)

Parameters

fileName string

The name of the file

loadType ImreadModes

The read mode

Properties

Bytes

Get or Set the raw image data

public byte[] Bytes { get; set; }

Property Value

byte[]

Cols

The number of columns

public int Cols { get; }

Property Value

int

Depth

Depth type

public DepthType Depth { get; }

Property Value

DepthType

Dims

The matrix dimensionality

public int Dims { get; }

Property Value

int

ElementSize

The size of the elements in this matrix

public int ElementSize { get; }

Property Value

int

IsContinuous

True if the data is continues

public bool IsContinuous { get; }

Property Value

bool

IsEmpty

True if the matrix is empty

public bool IsEmpty { get; }

Property Value

bool

IsSubmatrix

True if the matrix is a submatrix of another matrix

public bool IsSubmatrix { get; }

Property Value

bool

NumberOfChannels

Number of channels

public int NumberOfChannels { get; }

Property Value

int

Rows

The number of rows

public int Rows { get; }

Property Value

int

Size

The size of this matrix

public Size Size { get; }

Property Value

Size

Total

The method returns the number of array elements (a number of pixels if the array represents an image)

public nint Total { get; }

Property Value

nint

Methods

Clone()

Make a clone of the current UMat.

public UMat Clone()

Returns

UMat

A clone of the current 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

A matrix header for the specified matrix column.

ConvertTo(IOutputArray, DepthType, double, double)

Converts an array to another data type with optional scaling.

public void ConvertTo(IOutputArray m, DepthType rtype, double alpha = 1, double beta = 0)

Parameters

m IOutputArray

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

rtype DepthType

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(IOutputArray, IInputArray)

Copy the data in this umat to the other mat

public void CopyTo(IOutputArray m, IInputArray mask = null)

Parameters

m IOutputArray

The input array to copy to

mask IInputArray

Operation mask. Its non-zero elements indicate which matrix elements need to be copied.

CopyTo<T>(T[])

Copy data from this Mat to the managed array

public void CopyTo<T>(T[] data)

Parameters

data T[]

The managed array where data will be copied to.

Type Parameters

T

The type of managed data array

Create(int, int, DepthType, int, Usage)

Allocates new array data if needed.

public void Create(int rows, int cols, DepthType type, int channels, UMat.Usage usage = Usage.Default)

Parameters

rows int

New number of rows.

cols int

New number of columns.

type DepthType

New matrix element depth type.

channels int

New matrix number of channels

usage UMat.Usage

Allocation Usage

DeserializeObjectData(SerializationInfo, StreamingContext)

A function used for runtime deserailization of the object

protected virtual void DeserializeObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

Serialization info

context StreamingContext

Streaming context

DisposeObject()

Release all the unmanaged memory associated with this object.

protected override void DisposeObject()

Dot(IInputArray)

Computes the dot product of two mats

public double Dot(IInputArray mat)

Parameters

mat IInputArray

The matrix to compute dot product with

Returns

double

The dot product

Equals(UMat)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(UMat other)

Parameters

other UMat

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

GetData(bool)

Get a copy of the data values as an array

public Array GetData(bool jagged = true)

Parameters

jagged bool

If true, a jagged array will returned. Otherwise it will return a regular array.

Returns

Array

a copy of the data values as an array

GetInputArray()

Pointer to the InputArray

public InputArray GetInputArray()

Returns

InputArray

The input array

GetInputOutputArray()

Pointer to the InputOutputArray

public InputOutputArray GetInputOutputArray()

Returns

InputOutputArray

The input output array

GetMat(AccessType)

Return the Mat representation of the UMat

public Mat GetMat(AccessType access)

Parameters

access AccessType

The access type

Returns

Mat

The Mat representation of the UMat

GetObjectData(SerializationInfo, StreamingContext)

A function used for runtime serialization of the object

public void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

Serialization info

context StreamingContext

streaming context

GetOutputArray()

Pointer to the OutputArray

public OutputArray GetOutputArray()

Returns

OutputArray

The output array

MinMax(out double[], out double[], out Point[], out Point[])

Returns the min / max location and values for the image

public void MinMax(out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations)

Parameters

minValues double[]

The minimum values for each channel

maxValues double[]

The maximum values for each channel

minLocations Point[]

The minimum locations for each channel

maxLocations Point[]

The maximum locations for each channel

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

A new mat header that has different shape

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

A matrix header for the specified matrix row.

Save(string)

Save this image to the specific file.

public void Save(string fileName)

Parameters

fileName string

The name of the file to be saved to

Remarks

The image format is chosen depending on the filename extension, see cvLoadImage. Only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. If the format, depth or channel order is different, use cvCvtScale and cvCvtColor to convert it before saving, or use universal cvSave to save the image to XML or YAML format.

SetTo(IInputArray, IInputArray)

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

public void SetTo(IInputArray value, IInputArray mask = null)

Parameters

value IInputArray

Assigned scalar converted to the actual array type.

mask IInputArray

Operation mask of the same size as the umat.

SetTo(MCvScalar, IInputArray)

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

public void SetTo(MCvScalar value, IInputArray mask = null)

Parameters

value MCvScalar

Assigned scalar value.

mask IInputArray

Operation mask of the same size as the umat.

SetTo<T>(T[])

Copy data from managed array to this Mat

public void SetTo<T>(T[] data)

Parameters

data T[]

The managed array where data will be copied from

Type Parameters

T

The type of managed data array

Split()

Split current Image into an array of gray scale images where each element in the array represent a single color channel of the original image

public UMat[] Split()

Returns

UMat[]

An array of gray scale images where each element
in the array represent a single color channel of the original image

ToImage<TColor, TDepth>()

Convert this Mat to Image

public Image<TColor, TDepth> ToImage<TColor, TDepth>() where TColor : struct, IColor where TDepth : new()

Returns

Image<TColor, TDepth>

The image

Type Parameters

TColor

The type of Color

TDepth

The type of Depth

Operators

operator +(MCvScalar, UMat)

Element wise add mat with value

public static UMat operator +(MCvScalar value, UMat mat)

Parameters

value MCvScalar

The color to be added

mat UMat

The mat to be added

Returns

UMat

The images plus the color

operator +(UMat, MCvScalar)

Element wise add mat with value

public static UMat operator +(UMat mat, MCvScalar value)

Parameters

mat UMat

The mat to be added

value MCvScalar

The value to be added

Returns

UMat

The mat plus the value

operator +(UMat, UMat)

Element wise add mat1 with mat2

public static UMat operator +(UMat mat1, UMat mat2)

Parameters

mat1 UMat

The first mat to be added

mat2 UMat

The second mat to be added

Returns

UMat

The sum of the two images

operator +(UMat, double)

Element wise add mat with value

public static UMat operator +(UMat mat, double value)

Parameters

mat UMat

The mat to be added

value double

The value to be added

Returns

UMat

The images plus the value

operator +(double, UMat)

Element wise add mat1 with value

public static UMat operator +(double value, UMat mat1)

Parameters

value double

The value to be added

mat1 UMat

The mat to be added

Returns

UMat

The mat plus the value

operator &(MCvScalar, UMat)

Perform an element wise AND operation using a mat and a scalar

public static UMat operator &(MCvScalar val, UMat mat1)

Parameters

val MCvScalar

The scalar to AND

mat1 UMat

The first mat to AND

Returns

UMat

The result of the AND operation

operator &(UMat, MCvScalar)

Perform an element wise AND operation using a mat and a scalar

public static UMat operator &(UMat mat1, MCvScalar val)

Parameters

mat1 UMat

The first mat to AND

val MCvScalar

The value to AND

Returns

UMat

The result of the AND operation

operator &(UMat, UMat)

Perform an element wise AND operation on the two mats

public static UMat operator &(UMat mat1, UMat mat2)

Parameters

mat1 UMat

The first mat to AND

mat2 UMat

The second mat to AND

Returns

UMat

The result of the AND operation

operator &(UMat, double)

Perform an element wise AND operation using a mat and a scalar

public static UMat operator &(UMat mat1, double val)

Parameters

mat1 UMat

The first image to AND

val double

The value to AND

Returns

UMat

The result of the AND operation

operator &(double, UMat)

Perform an element wise AND operation using a mat and a color

public static UMat operator &(double val, UMat mat1)

Parameters

val double

The value to AND

mat1 UMat

The first mat to AND

Returns

UMat

The result of the AND operation

operator |(MCvScalar, UMat)

Perform an binary OR operation with some scalar

public static UMat operator |(MCvScalar val, UMat mat1)

Parameters

val MCvScalar

The color to OR

mat1 UMat

The mat to OR

Returns

UMat

The result of the OR operation

operator |(UMat, MCvScalar)

Perform an binary OR operation with some scalar

public static UMat operator |(UMat mat1, MCvScalar val)

Parameters

mat1 UMat

The mat to OR

val MCvScalar

The value to OR

Returns

UMat

The result of the OR operation

operator |(UMat, UMat)

Perform an element wise OR operation with another mat and return the result

public static UMat operator |(UMat mat1, UMat mat2)

Parameters

mat1 UMat

The first mat to apply bitwise OR operation

mat2 UMat

The second mat to apply bitwise OR operation

Returns

UMat

The result of the OR operation

operator |(UMat, double)

Perform an binary OR operation with some value

public static UMat operator |(UMat mat1, double val)

Parameters

mat1 UMat

The mat to OR

val double

The color to OR

Returns

UMat

The result of the OR operation

operator |(double, UMat)

Perform an binary OR operation with some color

public static UMat operator |(double val, UMat mat1)

Parameters

val double

The color to OR

mat1 UMat

The mat to OR

Returns

UMat

The result of the OR operation

operator /(UMat, double)

mat / scale

public static UMat operator /(UMat mat, double scale)

Parameters

mat UMat

The mat

scale double

The division scale

Returns

UMat

mat / scale

operator /(double, UMat)

scale / mat

public static UMat operator /(double scale, UMat mat)

Parameters

scale double

The scale

mat UMat

The mat

Returns

UMat

scale / mat

operator *(UMat, double)

mat * scale

public static UMat operator *(UMat mat, double scale)

Parameters

mat UMat

The mat

scale double

The multiplication scale

Returns

UMat

mat * scale

operator *(double, UMat)

scale*mat

public static UMat operator *(double scale, UMat mat)

Parameters

scale double

The multiplication scale

mat UMat

The mat

Returns

UMat

scale*mat

operator ~(UMat)

Compute the complement Mat

public static UMat operator ~(UMat mat)

Parameters

mat UMat

The mat to be inverted

Returns

UMat

The complement image

operator -(MCvScalar, UMat)

Element wise subtract value from the current mat

public static UMat operator -(MCvScalar value, UMat mat)

Parameters

value MCvScalar

The color to be subtracted

mat UMat

The mat to be subtracted

Returns

UMat

value - mat

operator -(UMat, MCvScalar)

Element wise subtract another mat from the current mat

public static UMat operator -(UMat mat, MCvScalar value)

Parameters

mat UMat

The mat to be subtracted

value MCvScalar

The value to be subtracted

Returns

UMat

The result of element wise subtracting value from mat

operator -(UMat, UMat)

Element wise subtract another mat from the current mat

public static UMat operator -(UMat mat1, UMat mat2)

Parameters

mat1 UMat

The mat to be subtracted from.

mat2 UMat

The second image to be subtracted from mat1

Returns

UMat

The result of element wise subtracting img2 from mat1

operator -(UMat, double)

Element wise subtract value from the current mat

public static UMat operator -(UMat mat, double value)

Parameters

mat UMat

The mat to be subtracted

value double

The value to be subtracted

Returns

UMat

mat - value

operator -(double, UMat)

value - mat

public static UMat operator -(double value, UMat mat)

Parameters

value double

The value to be subtracted

mat UMat

The mat to be subtracted

Returns

UMat

value - mat