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
sizeSize2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
sScalarAn optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .
usageFlagsUMatUsageFlagsusage 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
sizeSize2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType.CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
usageFlagsUMatUsageFlagsusage flags for allocator
UMat(UMat)
protected UMat(UMat m)
Parameters
mUMat
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
mUMatArray that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat::clone() .
rowRangeRangeRange of the m rows to take. As usual, the range start is inclusive and the range end is exclusive. Use Range.All to take all the rows.
colRangeRangeRange of the m columns to take. Use Range.All to take all the columns.
usageFlagsUMatUsageFlagsusage 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
mUMatArray that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat.Clone() .
rangesRange[]Array of selected ranges of m along each dimensionality.
UMat(UMat, Rect)
creates a matrix header for a part of the bigger matrix
public UMat(UMat m, Rect roi)
Parameters
mUMatArray that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the sub-array, use Mat.Clone() .
roiRectRegion of interest.
UMat(UMatUsageFlags)
Creates empty Mat
public UMat(UMatUsageFlags usageFlags = UMatUsageFlags.None)
Parameters
usageFlagsUMatUsageFlags
UMat(IEnumerable<int>, MatType)
constructs n-dimensional matrix
public UMat(IEnumerable<int> sizes, MatType type)
Parameters
sizesIEnumerable<int>Array of integers specifying an n-dimensional array shape.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
UMat(IEnumerable<int>, MatType, Scalar)
constructs n-dimensional matrix
public UMat(IEnumerable<int> sizes, MatType type, Scalar s)
Parameters
sizesIEnumerable<int>Array of integers specifying an n-dimensional array shape.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
sScalarAn optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .
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
rowsintNumber of rows in a 2D array.
colsintNumber of columns in a 2D array.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
sScalarAn optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .
usageFlagsUMatUsageFlagsusage 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
rowsintNumber of rows in a 2D array.
colsintNumber of columns in a 2D array.
typeMatTypeArray type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.
usageFlagsUMatUsageFlagsusage flags for allocator
Fields
TypeMap
typeof(T) -> MatType
protected static readonly IReadOnlyDictionary<Type, MatType> TypeMap
Field Value
Properties
Cols
the number of columns or -1 when the array has more than 2 dimensions
public int Cols { get; }
Property Value
Dims
the array dimensionality, >= 2
public int Dims { get; }
Property Value
Flags
includes several bit-fields:
- the magic signature
- continuity flag
- depth
- number of channels
public int Flags { get; }
Property Value
Height
the number of rows or -1 when the array has more than 2 dimensions
public int Height { get; }
Property Value
this[Range, Range]
Extracts a rectangular submatrix.
public UMat this[Range rowRange, Range colRange] { get; set; }
Parameters
rowRangeRangeStart and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All().
colRangeRangeStart and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All().
Property Value
this[Range[]]
Extracts a rectangular submatrix.
[SuppressMessage("Microsoft.Design", "CA1043: Use integral or string argument for indexers")]
public UMat this[params Range[] ranges] { get; set; }
Parameters
rangesRange[]Array of selected ranges along each array dimension.
Property Value
this[Rect]
Extracts a rectangular submatrix.
[SuppressMessage("Microsoft.Design", "CA1043: Use integral or string argument for indexers")]
public UMat this[Rect roi] { get; set; }
Parameters
roiRectExtracted submatrix specified as a rectangle.
Property Value
this[int, int, int, int]
Extracts a rectangular submatrix.
public UMat this[int rowStart, int rowEnd, int colStart, int colEnd] { get; set; }
Parameters
rowStartintStart row of the extracted submatrix. The upper boundary is not included.
rowEndintEnd row of the extracted submatrix. The upper boundary is not included.
colStartintStart column of the extracted submatrix. The upper boundary is not included.
colEndintEnd column of the extracted submatrix. The upper boundary is not included.
Property Value
this[Range, Range]
Extracts a rectangular submatrix.
public UMat this[Range rowRange, Range colRange] { get; set; }
Parameters
rowRangeRangeStart and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range.All().
colRangeRangeStart and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range.All().
Property Value
Rows
the number of rows or -1 when the array has more than 2 dimensions
public int Rows { get; }
Property Value
Width
the number of columns or -1 when the array has more than 2 dimensions
public int Width { get; }
Property Value
Methods
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
dtopintShift of the top submatrix boundary upwards.
dbottomintShift of the bottom submatrix boundary downwards.
dleftintShift of the left submatrix boundary to the left.
drightintShift of the right submatrix boundary to the right.
Returns
Alignment(int, UMatUsageFlags)
public UMat Alignment(int n = 4, UMatUsageFlags usageFlags = UMatUsageFlags.None)
Parameters
nintusageFlagsUMatUsageFlagsusage flags for allocator
Returns
AssignTo(UMat, MatType?)
Provides a functional form of convertTo.
public void AssignTo(UMat m, MatType? type = null)
Parameters
mUMatDestination array.
typeMatType?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
CheckVector(int, int, bool)
public int CheckVector(int elemChannels, int depth = -1, bool requireContinuous = true)
Parameters
elemChannelsintNumber of channels or number of columns the matrix should have. For a 2-D matrix, when the matrix has only 1 column, then it should have elemChannels channels; When the matrix has only 1 channel, then it should have elemChannels columns. For a 3-D matrix, it should have only one channel. Furthermore, if the number of planes is not one, then the number of rows within every plane has to be 1; if the number of rows within every plane is not 1, then the number of planes has to be 1.
depthintThe depth the matrix should have. Set it to -1 when any depth is fine.
requireContinuousboolSet it to true to require the matrix to be continuous
Returns
- int
-1 if the requirement is not satisfied. Otherwise, it returns the number of elements in the matrix. Note that an element may have multiple channels.
Clone()
Creates a full copy of the matrix.
public UMat Clone()
Returns
Clone(Rect)
Returns the partial Mat of the specified Mat
public UMat Clone(Rect roi)
Parameters
roiRect
Returns
Col(int)
Creates a matrix header for the specified matrix column.
public UMat Col(int x)
Parameters
xintA 0-based column index.
Returns
ColRange(Range)
Creates a matrix header for the specified column span.
public UMat ColRange(Range range)
Parameters
rangeRange
Returns
ColRange(int, int)
Creates a matrix header for the specified column span.
public UMat ColRange(int startCol, int endCol)
Parameters
startColintAn inclusive 0-based start index of the column span.
endColintAn exclusive 0-based ending index of the column span.
Returns
ColRange(Range)
Creates a matrix header for the specified column span.
public UMat ColRange(Range range)
Parameters
rangeRange
Returns
ConvertTo(OutputArray, MatType, double, double)
Converts an array to another data type with optional scaling.
public void ConvertTo(OutputArray m, MatType rtype, double alpha = 1, double beta = 0)
Parameters
mOutputArrayoutput matrix; if it does not have a proper size or type before the operation, it is reallocated.
rtypeMatTypedesired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.
alphadoubleoptional scale factor.
betadoubleoptional delta added to the scaled values.
CopyTo(OutputArray, InputArray?)
Copies the matrix to another one.
public void CopyTo(OutputArray m, InputArray? mask = null)
Parameters
mOutputArrayDestination matrix. If it does not have a proper size or type before the operation, it is reallocated.
maskInputArrayOperation mask. Its non-zero elements indicate which matrix elements need to be copied.
CopyTo(UMat, InputArray?)
Copies the matrix to another one.
public void CopyTo(UMat m, InputArray? mask = null)
Parameters
mUMatDestination matrix. If it does not have a proper size or type before the operation, it is reallocated.
maskInputArrayOperation mask. Its non-zero elements indicate which matrix elements need to be copied.
Create(MatType, params int[])
Allocates new array data if needed.
public void Create(MatType type, params int[] sizes)
Parameters
Create(Size, MatType)
Allocates new array data if needed.
public void Create(Size size, MatType type)
Parameters
Create(int, int, MatType)
Allocates new array data if needed.
public void Create(int rows, int cols, MatType type)
Parameters
Depth()
Returns the depth of a matrix element.
public int Depth()
Returns
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
dMatDiagTypeSingle-column matrix that forms a diagonal matrix or index of the diagonal, with the following values:
Returns
Diag(UMat)
Extracts a diagonal from a matrix, or creates a diagonal matrix.
public static UMat Diag(UMat d)
Parameters
dUMatOne-dimensional matrix that represents the main diagonal.
Returns
DisposeUnmanaged()
releases unmanaged resources
protected override void DisposeUnmanaged()
Dot(InputArray)
Computes a dot-product of two vectors.
public double Dot(InputArray m)
Parameters
mInputArrayanother dot-product operand.
Returns
ElemSize()
Returns the matrix element size in bytes.
public int ElemSize()
Returns
ElemSize1()
Returns the size of each matrix element channel in bytes.
public int ElemSize1()
Returns
Empty()
Returns true if the array has no elements.
public bool Empty()
Returns
EmptyClone(UMatUsageFlags)
Makes a Mat that have the same size, depth and channels as this image
public UMat EmptyClone(UMatUsageFlags usageFlags = UMatUsageFlags.None)
Parameters
usageFlagsUMatUsageFlags
Returns
Eye(Size, MatType)
Returns an identity matrix of the specified size and type.
public static UMat Eye(Size size, MatType type)
Parameters
sizeSizeAlternative to the matrix size specification Size(cols, rows) .
typeMatTypeCreated matrix type.
Returns
Eye(int, int, MatType)
Returns an identity matrix of the specified size and type.
public static UMat Eye(int rows, int cols, MatType type)
Parameters
Returns
FromNativePointer(nint)
Creates from native cv::UMat* pointer
public static UMat FromNativePointer(nint ptr)
Parameters
ptrnint
Returns
GetMat(AccessFlag)
Returns the UMat data as a Mat.
public Mat GetMat(AccessFlag accessFlags)
Parameters
accessFlagsAccessFlagAccessFlag determining the mode in which the data is to be acquired
Returns
Inv(DecompTypes)
Inverses a matrix.
public UMat Inv(DecompTypes method = DecompTypes.LU)
Parameters
methodDecompTypesMatrix inversion method
Returns
IsContinuous()
Reports whether the matrix is continuous or not.
public bool IsContinuous()
Returns
IsSubmatrix()
Returns whether this matrix is a part of other matrix or not.
public bool IsSubmatrix()
Returns
LocateROI(out Size, out Point)
Locates the matrix header within a parent matrix.
public void LocateROI(out Size wholeSize, out Point ofs)
Parameters
wholeSizeSizeOutput parameter that contains the size of the whole matrix containing *this as a part.
ofsPointOutput parameter that contains an offset of *this inside the whole matrix.
Mul(InputArray, double)
Performs an element-wise multiplication or division of the two matrices.
public UMat Mul(InputArray m, double scale = 1)
Parameters
mInputArrayscaledouble
Returns
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
Returns
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
sizeSizeAlternative to the matrix size specification Size(cols, rows) .
typeMatTypeCreated matrix type.
Returns
Ones(int, int, MatType)
Returns an array of all 1’s of the specified size and type.
public static UMat Ones(int rows, int cols, MatType type)
Parameters
Returns
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
cnintNew number of channels. If the parameter is 0, the number of channels remains the same.
rowsintNew number of rows. If the parameter is 0, the number of rows remains the same.
Returns
Reshape(int, params int[])
Changes the shape and/or the number of channels of a 2D matrix without copying the data.
public UMat Reshape(int cn, params int[] newDims)
Parameters
cnintNew number of channels. If the parameter is 0, the number of channels remains the same.
newDimsint[]New number of rows. If the parameter is 0, the number of rows remains the same.
Returns
Row(int)
Creates a matrix header for the specified matrix row.
public UMat Row(int y)
Parameters
yintA 0-based row index.
Returns
RowRange(Range)
Creates a matrix header for the specified row span.
public UMat RowRange(Range range)
Parameters
rangeRange
Returns
RowRange(int, int)
Creates a matrix header for the specified row span.
public UMat RowRange(int startRow, int endRow)
Parameters
Returns
RowRange(Range)
Creates a matrix header for the specified row span.
public UMat RowRange(Range range)
Parameters
rangeRange
Returns
SetTo(InputArray, UMat?)
Sets all or some of the array elements to the specified value.
public UMat SetTo(InputArray value, UMat? mask = null)
Parameters
valueInputArraymaskUMat
Returns
SetTo(Scalar, UMat?)
Sets all or some of the array elements to the specified value.
public UMat SetTo(Scalar value, UMat? mask = null)
Parameters
Returns
Size()
Returns a matrix size.
public Size Size()
Returns
Size(int)
Returns a matrix size.
public int Size(int dim)
Parameters
dimint
Returns
Step()
Returns number of bytes each matrix row occupies.
public long Step()
Returns
Step(int)
Returns number of bytes each matrix row occupies.
public long Step(int i)
Parameters
iint
Returns
Step1(int)
Returns a normalized step.
public long Step1(int i = 0)
Parameters
iint
Returns
SubMat(Range, Range)
Extracts a rectangular submatrix.
public UMat SubMat(Range rowRange, Range colRange)
Parameters
rowRangeRangeStart and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range::all().
colRangeRangeStart and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range::all().
Returns
SubMat(params Range[])
Extracts a rectangular submatrix.
public UMat SubMat(params Range[] ranges)
Parameters
rangesRange[]Array of selected ranges along each array dimension.
Returns
SubMat(Rect)
Extracts a rectangular submatrix.
public UMat SubMat(Rect roi)
Parameters
roiRectExtracted submatrix specified as a rectangle.
Returns
SubMat(int, int, int, int)
Extracts a rectangular submatrix.
public UMat SubMat(int rowStart, int rowEnd, int colStart, int colEnd)
Parameters
Returns
SubMat(Range, Range)
Extracts a rectangular submatrix.
public UMat SubMat(Range rowRange, Range colRange)
Parameters
rowRangeRangeStart and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range::all().
colRangeRangeStart and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range::all().
Returns
T()
Transposes a matrix.
public UMat T()
Returns
ToString()
Returns a string that represents this Mat.
public override string ToString()
Returns
Total()
Returns the total number of array elements.
public long Total()
Returns
Type()
Returns the type of a matrix element.
public MatType Type()
Returns
Zeros(MatType, params int[])
Returns a zero array of the specified size and type.
public static UMat Zeros(MatType type, params int[] sizes)
Parameters
Returns
Zeros(Size, MatType)
Returns a zero array of the specified size and type.
public static UMat Zeros(Size size, MatType type)
Parameters
sizeSizeAlternative to the matrix size specification Size(cols, rows) .
typeMatTypeCreated matrix type.
Returns
Zeros(int, int, MatType)
Returns a zero array of the specified size and type.
public static UMat Zeros(int rows, int cols, MatType type)