Class GpuMat
A GpuMat, use the generic version if possible. The non generic version is good for use as buffer in stream calls.
public class GpuMat : UnmanagedObject, IEquatable<GpuMat>, IInputOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays, IOutputArray, IInputArray, IDisposable
- Inheritance
-
GpuMat
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
GpuMat()
Create an empty GpuMat
public GpuMat()
GpuMat(GpuMat, Range, Range)
Create a GpuMat from the specific region of mat
. The data is shared between the two GpuMat
public GpuMat(GpuMat mat, Range rowRange, Range colRange)
Parameters
mat
GpuMatThe matrix where the region is extracted from
rowRange
RangeThe row range.
colRange
RangeThe column range.
GpuMat(IInputArray)
Create a GpuMat from an CvArray of the same depth type
public GpuMat(IInputArray arr)
Parameters
arr
IInputArrayThe CvArray to be converted to GpuMat
GpuMat(int, int, DepthType, int, bool)
Create a GpuMat of the specified size
public GpuMat(int rows, int cols, DepthType depthType, int channels, bool continuous = false)
Parameters
rows
intThe number of rows (height)
cols
intThe number of columns (width)
depthType
DepthTypeThe type of depth
channels
intThe number of channels
continuous
boolIndicates if the data should be continuous
GpuMat(int, int, DepthType, int, nint, int)
Create a GpuMat pointing to user-allocated data
public GpuMat(int rows, int cols, DepthType depthType, int channels, nint data, int step = 0)
Parameters
rows
intThe number of rows (height)
cols
intThe number of columns (width)
depthType
DepthTypeThe type of depth
channels
intThe number of channels
data
nintUser allocated data
step
intUse 0 for auto matically calculated step. Or specify the data step here.
Properties
Depth
Depth type
public DepthType Depth { get; }
Property Value
IsContinuous
True if the data is continues
public bool IsContinuous { get; }
Property Value
IsEmpty
True if the matrix is empty
public bool IsEmpty { get; }
Property Value
NumberOfChannels
Number of channels
public int NumberOfChannels { get; }
Property Value
Size
Get the GpuMat size: width == number of columns, height == number of rows
public Size Size { get; }
Property Value
Type
Get the type of the GpuMat
public int Type { get; }
Property Value
Methods
Clone()
Make a clone of the GpuMat
public object Clone()
Returns
- object
A clone of the GPU Mat
Col(int)
Returns a GpuMat corresponding to the ith column of the GpuMat. The data is shared with the current GpuMat.
public GpuMat Col(int i)
Parameters
i
intThe column to be extracted
Returns
- GpuMat
The ith column of the GpuMat
Remarks
The parent GpuMat should never be released before the returned GpuMat that represent the subregion
ColRange(int, int)
Returns a GpuMat corresponding to the [start
end
) columns of the GpuMat. The data is shared with the current GpuMat.
public GpuMat ColRange(int start, int end)
Parameters
start
intThe inclusive stating column to be extracted
end
intThe exclusive ending column to be extracted
Returns
- GpuMat
The [
start
end
) columns of the GpuMat
Remarks
The parent GpuMat should never be released before the returned GpuMat that represent the subregion
ConvertTo(IOutputArray, DepthType, double, double, Stream)
This function has several different purposes and thus has several synonyms. It copies one GpuMat to another with optional scaling, which is performed first, and/or optional type conversion, performed after: dst(I)=src(I)*scale + (shift,shift,...) All the channels of multi-channel GpuMats are processed independently. The type conversion is done with rounding and saturation, that is if a result of scaling + conversion can not be represented exactly by a value of destination GpuMat element type, it is set to the nearest representable value on the real axis. In case of scale=1, shift=0 no prescaling is done. This is a specially optimized case and it has the appropriate convertTo synonym.
public void ConvertTo(IOutputArray dst, DepthType rtype, double scale = 1, double shift = 0, Stream stream = null)
Parameters
dst
IOutputArrayDestination GpuMat
rtype
DepthTypeResult type
scale
doubleScale factor
shift
doubleValue added to the scaled source GpuMat elements
stream
StreamUse a Stream to call the function asynchronously (non-blocking) or IntPtr.Zero to call the function synchronously (blocking).
CopyTo(IOutputArray, IInputArray, Stream)
Copy the source GpuMat to destination GpuMat, using an optional mask.
public void CopyTo(IOutputArray dst, IInputArray mask = null, Stream stream = null)
Parameters
dst
IOutputArrayThe output array to be copied to
mask
IInputArrayThe optional mask, use IntPtr.Zero if not needed.
stream
StreamUse a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).
Create(int, int, DepthType, int)
allocates new GpuMat data unless the GpuMat already has specified size and type
public void Create(int rows, int cols, DepthType depthType, int channels)
Parameters
rows
intThe number of rows
cols
intThe number of cols
depthType
DepthTypeThe depth type
channels
intThe number of channels.
DisposeObject()
Release the unmanaged memory associated with this GpuMat
protected override void DisposeObject()
Download(IOutputArray, Stream)
Downloads data from device to host memory.
public void Download(IOutputArray arr, Stream stream = null)
Parameters
arr
IOutputArrayThe destination CvArray where the GpuMat data will be downloaded to.
stream
StreamUse a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).
Equals(GpuMat)
Returns true if the two GpuMat equals
public bool Equals(GpuMat other)
Parameters
other
GpuMatThe other GpuMat to be compares with
Returns
- bool
True if the two GpuMat equals
GetData(bool)
Get a copy of the data values as an array
public Array GetData(bool jagged = true)
Parameters
jagged
boolIf 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
GetOutputArray()
Pointer to the OutputArray
public OutputArray GetOutputArray()
Returns
- OutputArray
The output array
MergeFrom(GpuMat[], Stream)
Makes multi-channel array out of several single-channel arrays
public void MergeFrom(GpuMat[] gpuMats, Stream stream = null)
Parameters
gpuMats
GpuMat[]An array of single channel GpuMat where each item in the array represent a single channel of the GpuMat
stream
StreamUse a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).
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 shape of GpuMat without copying data.
public GpuMat Reshape(int newCn, int newRows = 0)
Parameters
newCn
intNew number of channels. newCn = 0 means that the number of channels remains unchanged.
newRows
intNew number of rows. newRows = 0 means that the number of rows remains unchanged unless it needs to be changed according to newCn value.
Returns
- GpuMat
A GpuMat of different shape
Row(int)
Returns a GpuMat corresponding to the ith row of the GpuMat. The data is shared with the current GpuMat.
public GpuMat Row(int i)
Parameters
i
intThe row to be extracted
Returns
- GpuMat
The ith row of the GpuMat
Remarks
The parent GpuMat should never be released before the returned GpuMat that represent the subregion
RowRange(int, int)
Returns a GpuMat corresponding to the [start
end
) rows of the GpuMat. The data is shared with the current GpuMat.
public GpuMat RowRange(int start, int end)
Parameters
start
intThe inclusive stating row to be extracted
end
intThe exclusive ending row to be extracted
Returns
- GpuMat
The [
start
end
) rows of the GpuMat
Remarks
The parent GpuMat should never be released before the returned GpuMat that represent the subregion
Save(string)
Save the GpuMat to a file
public void Save(string fileName)
Parameters
fileName
stringThe file name
SetTo(MCvScalar, IInputArray, Stream)
Copies scalar value to every selected element of the destination GpuMat: arr(I)=value if mask(I)!=0
public void SetTo(MCvScalar value, IInputArray mask = null, Stream stream = null)
Parameters
value
MCvScalarFill value
mask
IInputArrayOperation mask, 8-bit single channel GpuMat; specifies elements of destination GpuMat to be changed. Can be IntPtr.Zero if not used
stream
StreamUse a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).
Split(Stream)
Split current GpuMat into an array of single channel GpuMat where each element in the array represent a single channel of the original GpuMat
public GpuMat[] Split(Stream stream = null)
Parameters
stream
StreamUse a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).
Returns
- GpuMat[]
An array of single channel GpuMat where each element
in the array represent a single channel of the original GpuMat
ToMat()
Convert the GpuMat to Mat
public Mat ToMat()
Returns
- Mat
The Mat that contains the same data as this GpuMat
Upload(IInputArray, Stream)
Upload data to GpuMat
public void Upload(IInputArray arr, Stream stream = null)
Parameters
arr
IInputArrayThe CvArray to be uploaded to GpuMat
stream
StreamUse a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).