Class SparseMat
- Namespace
- OpenCvSharp
- Assembly
- OpenCvSharp.dll
Sparse matrix class.
public class SparseMat : DisposableCvObject, IDisposable, ICvPtrHolder
- Inheritance
-
SparseMat
- Implements
- Inherited Members
Constructors
SparseMat()
Creates empty SparseMat
public SparseMat()
SparseMat(Mat)
converts old-style CvMat to the new matrix; the data is not copied by default
public SparseMat(Mat m)
Parameters
mMatcv::Mat object
SparseMat(IEnumerable<int>, MatType)
constructs n-dimensional sparse matrix
[SuppressMessage("Maintainability", "CA1508: Avoid dead conditional code")]
public SparseMat(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.
SparseMat(nint)
Creates from native cv::SparseMat* pointer
public SparseMat(nint ptr)
Parameters
ptrnint
Methods
AddRef()
manually increments the reference counter to the header.
public void AddRef()
AssignFrom(Mat)
Assignment operator. equivalent to the corresponding constructor.
public SparseMat AssignFrom(Mat m)
Parameters
mMat
Returns
AssignFrom(SparseMat)
Assignment operator. This is O(1) operation, i.e. no data is copied
public SparseMat AssignFrom(SparseMat m)
Parameters
Returns
AssignTo(SparseMat, MatType?)
not used now
public void AssignTo(SparseMat m, MatType? type = null)
Parameters
Channels()
Returns the number of sparse matrix channels.
public int Channels()
Returns
Clear()
sets all the sparse matrix elements to 0, which means clearing the hash table.
public void Clear()
Clone()
creates full copy of the matrix
public SparseMat Clone()
Returns
ConvertTo(Mat, MatType, double, double)
converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.
public void ConvertTo(Mat m, MatType rtype, double alpha = 1, double beta = 0)
Parameters
mMatrtypeMatTypeThe output matrix data type. When it is =-1, the output array will have the same data type as (*this)
alphadoubleThe scale factor
betadoubleThe optional delta added to the scaled values before the conversion
ConvertTo(SparseMat, MatType, double)
multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type
public void ConvertTo(SparseMat m, MatType rtype, double alpha = 1)
Parameters
CopyTo(Mat)
converts sparse matrix to dense matrix.
public void CopyTo(Mat m)
Parameters
mMat
CopyTo(SparseMat)
copies all the data to the destination matrix. All the previous content of m is erased.
public void CopyTo(SparseMat m)
Parameters
Create(MatType, params int[])
Reallocates sparse matrix. If the matrix already had the proper size and type, it is simply cleared with clear(), otherwise, the old matrix is released (using release()) and the new one is allocated.
[SuppressMessage("Maintainability", "CA1508: Avoid dead conditional code")]
public void Create(MatType type, params int[] sizes)
Parameters
Depth()
Returns the depth of sparse matrix element.
public int Depth()
Returns
Dims()
Returns the matrix dimensionality
public int Dims()
Returns
DisposeUnmanaged()
Releases unmanaged resources
protected override void DisposeUnmanaged()
ElemSize()
returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements)
public int ElemSize()
Returns
ElemSize1()
returns elemSize()/channels()
public int ElemSize1()
Returns
Find<T>(int, int, int, long?)
Return pthe specified sparse matrix element if it exists; otherwise, null.
public T? Find<T>(int i0, int i1, int i2, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T?
Type Parameters
T
Find<T>(int, int, long?)
Return pthe specified sparse matrix element if it exists; otherwise, null.
public T? Find<T>(int i0, int i1, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T?
Type Parameters
T
Find<T>(int, long?)
Return pthe specified sparse matrix element if it exists; otherwise, null.
public T? Find<T>(int i0, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T?
Type Parameters
T
Find<T>(int[], long?)
Return pthe specified sparse matrix element if it exists; otherwise, null.
public T? Find<T>(int[] idx, long? hashVal = null) where T : struct
Parameters
idxint[]Array of Mat::dims indices.
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T?
Type Parameters
T
FromMat(Mat)
Create SparseMat from Mat
public static SparseMat FromMat(Mat mat)
Parameters
matMat
Returns
GetIndexer<T>()
Gets a type-specific indexer. The indexer has getters/setters to access each matrix element.
public SparseMat.Indexer<T> GetIndexer<T>() where T : struct
Returns
Type Parameters
T
Get<T>(int, int, int, long?)
Returns a value to the specified array element.
public T Get<T>(int i0, int i1, int i2, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T
A value to the specified array element.
Type Parameters
T
Get<T>(int, int, long?)
Returns a value to the specified array element.
public T Get<T>(int i0, int i1, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T
A value to the specified array element.
Type Parameters
T
Get<T>(int, long?)
Returns a value to the specified array element.
public T Get<T>(int i0, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T
A value to the specified array element.
Type Parameters
T
Get<T>(int[], long?)
Returns a value to the specified array element.
public T Get<T>(int[] idx, long? hashVal = null) where T : struct
Parameters
idxint[]Array of Mat::dims indices.
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T
A value to the specified array element.
Type Parameters
T
Hash(int)
Computes the element hash value (1D case)
public long Hash(int i0)
Parameters
i0intIndex along the dimension 0
Returns
Hash(int, int)
Computes the element hash value (2D case)
public long Hash(int i0, int i1)
Parameters
Returns
Hash(int, int, int)
Computes the element hash value (3D case)
public long Hash(int i0, int i1, int i2)
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
Returns
Hash(params int[])
Computes the element hash value (nD case)
public long Hash(params int[] idx)
Parameters
idxint[]Array of Mat::dims indices.
Returns
NzCount()
returns the number of non-zero elements (=the number of hash table nodes)
public long NzCount()
Returns
Ptr(int, bool, long?)
Low-level element-access function.
public nint Ptr(int i0, bool createMissing, long? hashVal = null)
Parameters
i0intIndex along the dimension 0
createMissingboolCreate new element with 0 value if it does not exist in SparseMat.
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
Ptr(int, int, bool, long?)
Low-level element-access function.
public nint Ptr(int i0, int i1, bool createMissing, long? hashVal = null)
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
createMissingboolCreate new element with 0 value if it does not exist in SparseMat.
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
Ptr(int, int, int, bool, long?)
Low-level element-access function.
public nint Ptr(int i0, int i1, int i2, bool createMissing, long? hashVal = null)
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
createMissingboolCreate new element with 0 value if it does not exist in SparseMat.
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
Ptr(int[], bool, long?)
Low-level element-access function.
public nint Ptr(int[] idx, bool createMissing, long? hashVal = null)
Parameters
idxint[]Array of Mat::dims indices.
createMissingboolCreate new element with 0 value if it does not exist in SparseMat.
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
Ref<T>()
Gets a type-specific indexer. The indexer has getters/setters to access each matrix element.
public SparseMat.Indexer<T> Ref<T>() where T : struct
Returns
Type Parameters
T
Release()
Releases the resources
public void Release()
Set<T>(int, int, int, T, long?)
Set a value to the specified array element.
public void Set<T>(int i0, int i1, int i2, T value, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
valueThashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Type Parameters
T
Set<T>(int, int, T, long?)
Set a value to the specified array element.
public void Set<T>(int i0, int i1, T value, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
valueThashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Type Parameters
T
Set<T>(int, T, long?)
Set a value to the specified array element.
public void Set<T>(int i0, T value, long? hashVal = null) where T : struct
Parameters
Type Parameters
T
Set<T>(int[], T, long?)
Set a value to the specified array element.
public void Set<T>(int[] idx, T value, long? hashVal = null) where T : struct
Parameters
idxint[]Array of Mat::dims indices.
valueThashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Type Parameters
T
Size()
Returns the array of sizes, or null if the matrix is not allocated
public int[] Size()
Returns
- int[]
Size(int)
Returns the size of i-th matrix dimension (or 0)
public int Size(int dim)
Parameters
dimint
Returns
ToString()
Returns a string that represents this Mat.
public override string ToString()
Returns
Type()
Returns the type of sparse matrix element.
public MatType Type()
Returns
Value<T>(int, int, int, long?)
Return pthe specified sparse matrix element if it exists; otherwise, default(T).
public T Value<T>(int i0, int i1, int i2, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
i2intIndex along the dimension 2
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T
Type Parameters
T
Value<T>(int, int, long?)
Return pthe specified sparse matrix element if it exists; otherwise, default(T).
public T Value<T>(int i0, int i1, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
i1intIndex along the dimension 1
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T
Type Parameters
T
Value<T>(int, long?)
Return pthe specified sparse matrix element if it exists; otherwise, default(T).
public T Value<T>(int i0, long? hashVal = null) where T : struct
Parameters
i0intIndex along the dimension 0
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T
Type Parameters
T
Value<T>(int[], long?)
Return pthe specified sparse matrix element if it exists; otherwise, default(T).
public T Value<T>(int[] idx, long? hashVal = null) where T : struct
Parameters
idxint[]Array of Mat::dims indices.
hashVallong?If hashVal is not null, the element hash value is not computed but hashval is taken instead.
Returns
- T
Type Parameters
T