Class SparseMat
Sparse matrix class.
Implements
Inherited Members
Namespace: OpenCvSharp
Assembly: OpenCvSharp.dll
Syntax
public class SparseMat : DisposableCvObject, ICvPtrHolder
Constructors
| Improve this Doc View SourceSparseMat()
Creates empty SparseMat
Declaration
public SparseMat()
SparseMat(IEnumerable<Int32>, MatType)
constructs n-dimensional sparse matrix
Declaration
public SparseMat(IEnumerable<int> sizes, MatType type)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.Int32> | sizes | Array of integers specifying an n-dimensional array shape. |
OpenCvSharp.MatType | type | 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. |
SparseMat(IntPtr)
Creates from native cv::SparseMat* pointer
Declaration
public SparseMat(IntPtr ptr)
Parameters
Type | Name | Description |
---|---|---|
IntPtr | ptr |
SparseMat(Mat)
converts old-style CvMat to the new matrix; the data is not copied by default
Declaration
public SparseMat(Mat m)
Parameters
Type | Name | Description |
---|---|---|
Mat | m | cv::Mat object |
Methods
| Improve this Doc View SourceAddRef()
manually increments the reference counter to the header.
Declaration
public void AddRef()
AssignFrom(Mat)
Assignment operator. equivalent to the corresponding constructor.
Declaration
public SparseMat AssignFrom(Mat m)
Parameters
Type | Name | Description |
---|---|---|
Mat | m |
Returns
Type | Description |
---|---|
SparseMat |
AssignFrom(SparseMat)
Assignment operator. This is O(1) operation, i.e. no data is copied
Declaration
public SparseMat AssignFrom(SparseMat m)
Parameters
Type | Name | Description |
---|---|---|
SparseMat | m |
Returns
Type | Description |
---|---|
SparseMat |
AssignTo(SparseMat, Nullable<MatType>)
not used now
Declaration
public void AssignTo(SparseMat m, MatType? type = null)
Parameters
Type | Name | Description |
---|---|---|
SparseMat | m | |
System.Nullable<OpenCvSharp.MatType> | type |
Channels()
Returns the number of sparse matrix channels.
Declaration
public int Channels()
Returns
Type | Description |
---|---|
System.Int32 |
Clear()
sets all the sparse matrix elements to 0, which means clearing the hash table.
Declaration
public void Clear()
Clone()
creates full copy of the matrix
Declaration
public SparseMat Clone()
Returns
Type | Description |
---|---|
SparseMat |
ConvertTo(Mat, MatType, Double, Double)
converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.
Declaration
public void ConvertTo(Mat m, MatType rtype, double alpha = 1, double beta = 0)
Parameters
Type | Name | Description |
---|---|---|
Mat | m | |
OpenCvSharp.MatType | rtype | The output matrix data type. When it is =-1, the output array will have the same data type as (*this) |
System.Double | alpha | The scale factor |
System.Double | beta | The 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
Declaration
public void ConvertTo(SparseMat m, MatType rtype, double alpha = 1)
Parameters
Type | Name | Description |
---|---|---|
SparseMat | m | |
OpenCvSharp.MatType | rtype | |
System.Double | alpha |
CopyTo(Mat)
converts sparse matrix to dense matrix.
Declaration
public void CopyTo(Mat m)
Parameters
Type | Name | Description |
---|---|---|
Mat | m |
CopyTo(SparseMat)
copies all the data to the destination matrix. All the previous content of m is erased.
Declaration
public void CopyTo(SparseMat m)
Parameters
Type | Name | Description |
---|---|---|
SparseMat | m |
Create(MatType, Int32[])
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.
Declaration
public void Create(MatType type, params int[] sizes)
Parameters
Type | Name | Description |
---|---|---|
OpenCvSharp.MatType | type | |
System.Int32[] | sizes |
Depth()
Returns the depth of sparse matrix element.
Declaration
public int Depth()
Returns
Type | Description |
---|---|
System.Int32 |
Dims()
Returns the matrix dimensionality
Declaration
public int Dims()
Returns
Type | Description |
---|---|
System.Int32 |
DisposeUnmanaged()
Releases unmanaged resources
Declaration
protected override void DisposeUnmanaged()
Overrides
| Improve this Doc View SourceElemSize()
returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements)
Declaration
public int ElemSize()
Returns
Type | Description |
---|---|
System.Int32 |
ElemSize1()
returns elemSize()/channels()
Declaration
public int ElemSize1()
Returns
Type | Description |
---|---|
System.Int32 |
Find<T>(Int32, Int32, Int32, Nullable<Int64>)
Return pthe specified sparse matrix element if it exists; otherwise, null.
Declaration
public T? Find<T>(int i0, int i1, int i2, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Int32 | i2 | Index along the dimension 2 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
System.Nullable<T> |
Type Parameters
Name | Description |
---|---|
T |
Find<T>(Int32, Int32, Nullable<Int64>)
Return pthe specified sparse matrix element if it exists; otherwise, null.
Declaration
public T? Find<T>(int i0, int i1, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
System.Nullable<T> |
Type Parameters
Name | Description |
---|---|
T |
Find<T>(Int32, Nullable<Int64>)
Return pthe specified sparse matrix element if it exists; otherwise, null.
Declaration
public T? Find<T>(int i0, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
System.Nullable<T> |
Type Parameters
Name | Description |
---|---|
T |
Find<T>(Int32[], Nullable<Int64>)
Return pthe specified sparse matrix element if it exists; otherwise, null.
Declaration
public T? Find<T>(int[] idx, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | idx | Array of Mat::dims indices. |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
System.Nullable<T> |
Type Parameters
Name | Description |
---|---|
T |
FromMat(Mat)
Create SparseMat from Mat
Declaration
public static SparseMat FromMat(Mat mat)
Parameters
Type | Name | Description |
---|---|---|
Mat | mat |
Returns
Type | Description |
---|---|
SparseMat |
Get<T>(Int32, Int32, Int32, Nullable<Int64>)
Returns a value to the specified array element.
Declaration
public T Get<T>(int i0, int i1, int i2, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Int32 | i2 | Index along the dimension 2 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
T | A value to the specified array element. |
Type Parameters
Name | Description |
---|---|
T |
Get<T>(Int32, Int32, Nullable<Int64>)
Returns a value to the specified array element.
Declaration
public T Get<T>(int i0, int i1, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
T | A value to the specified array element. |
Type Parameters
Name | Description |
---|---|
T |
Get<T>(Int32, Nullable<Int64>)
Returns a value to the specified array element.
Declaration
public T Get<T>(int i0, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
T | A value to the specified array element. |
Type Parameters
Name | Description |
---|---|
T |
Get<T>(Int32[], Nullable<Int64>)
Returns a value to the specified array element.
Declaration
public T Get<T>(int[] idx, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | idx | Array of Mat::dims indices. |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
T | A value to the specified array element. |
Type Parameters
Name | Description |
---|---|
T |
GetIndexer<T>()
Gets a type-specific indexer. The indexer has getters/setters to access each matrix element.
Declaration
public SparseMat.Indexer<T> GetIndexer<T>()
where T : struct
Returns
Type | Description |
---|---|
SparseMat.Indexer<T> |
Type Parameters
Name | Description |
---|---|
T |
Hash(Int32)
Computes the element hash value (1D case)
Declaration
public long Hash(int i0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
Returns
Type | Description |
---|---|
System.Int64 |
Hash(Int32, Int32)
Computes the element hash value (2D case)
Declaration
public long Hash(int i0, int i1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
Returns
Type | Description |
---|---|
System.Int64 |
Hash(Int32, Int32, Int32)
Computes the element hash value (3D case)
Declaration
public long Hash(int i0, int i1, int i2)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Int32 | i2 | Index along the dimension 2 |
Returns
Type | Description |
---|---|
System.Int64 |
Hash(Int32[])
Computes the element hash value (nD case)
Declaration
public long Hash(params int[] idx)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | idx | Array of Mat::dims indices. |
Returns
Type | Description |
---|---|
System.Int64 |
NzCount()
returns the number of non-zero elements (=the number of hash table nodes)
Declaration
public long NzCount()
Returns
Type | Description |
---|---|
System.Int64 |
Ptr(Int32, Boolean, Nullable<Int64>)
Low-level element-access function.
Declaration
public IntPtr Ptr(int i0, bool createMissing, long? hashVal = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Boolean | createMissing | Create new element with 0 value if it does not exist in SparseMat. |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
IntPtr |
Ptr(Int32, Int32, Boolean, Nullable<Int64>)
Low-level element-access function.
Declaration
public IntPtr Ptr(int i0, int i1, bool createMissing, long? hashVal = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Boolean | createMissing | Create new element with 0 value if it does not exist in SparseMat. |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
IntPtr |
Ptr(Int32, Int32, Int32, Boolean, Nullable<Int64>)
Low-level element-access function.
Declaration
public IntPtr Ptr(int i0, int i1, int i2, bool createMissing, long? hashVal = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Int32 | i2 | Index along the dimension 2 |
System.Boolean | createMissing | Create new element with 0 value if it does not exist in SparseMat. |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
IntPtr |
Ptr(Int32[], Boolean, Nullable<Int64>)
Low-level element-access function.
Declaration
public IntPtr Ptr(int[] idx, bool createMissing, long? hashVal = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | idx | Array of Mat::dims indices. |
System.Boolean | createMissing | Create new element with 0 value if it does not exist in SparseMat. |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
IntPtr |
Ref<T>()
Gets a type-specific indexer. The indexer has getters/setters to access each matrix element.
Declaration
public SparseMat.Indexer<T> Ref<T>()
where T : struct
Returns
Type | Description |
---|---|
SparseMat.Indexer<T> |
Type Parameters
Name | Description |
---|---|
T |
Release()
Releases the resources
Declaration
public void Release()
Set<T>(Int32, T, Nullable<Int64>)
Set a value to the specified array element.
Declaration
public void Set<T>(int i0, T value, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
T | value | |
System.Nullable<System.Int64> | hashVal |
Type Parameters
Name | Description |
---|---|
T |
Set<T>(Int32, Int32, T, Nullable<Int64>)
Set a value to the specified array element.
Declaration
public void Set<T>(int i0, int i1, T value, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
T | value | |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Type Parameters
Name | Description |
---|---|
T |
Set<T>(Int32, Int32, Int32, T, Nullable<Int64>)
Set a value to the specified array element.
Declaration
public void Set<T>(int i0, int i1, int i2, T value, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Int32 | i2 | Index along the dimension 2 |
T | value | |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Type Parameters
Name | Description |
---|---|
T |
Set<T>(Int32[], T, Nullable<Int64>)
Set a value to the specified array element.
Declaration
public void Set<T>(int[] idx, T value, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | idx | Array of Mat::dims indices. |
T | value | |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Type Parameters
Name | Description |
---|---|
T |
Size()
Returns the array of sizes, or null if the matrix is not allocated
Declaration
public int[] Size()
Returns
Type | Description |
---|---|
System.Int32[] |
Size(Int32)
Returns the size of i-th matrix dimension (or 0)
Declaration
public int Size(int dim)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | dim |
Returns
Type | Description |
---|---|
System.Int32 |
ToString()
Returns a string that represents this Mat.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Type()
Returns the type of sparse matrix element.
Declaration
public MatType Type()
Returns
Type | Description |
---|---|
OpenCvSharp.MatType |
Value<T>(Int32, Int32, Int32, Nullable<Int64>)
Return pthe specified sparse matrix element if it exists; otherwise, default(T).
Declaration
public T Value<T>(int i0, int i1, int i2, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Int32 | i2 | Index along the dimension 2 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Value<T>(Int32, Int32, Nullable<Int64>)
Return pthe specified sparse matrix element if it exists; otherwise, default(T).
Declaration
public T Value<T>(int i0, int i1, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Int32 | i1 | Index along the dimension 1 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Value<T>(Int32, Nullable<Int64>)
Return pthe specified sparse matrix element if it exists; otherwise, default(T).
Declaration
public T Value<T>(int i0, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i0 | Index along the dimension 0 |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Value<T>(Int32[], Nullable<Int64>)
Return pthe specified sparse matrix element if it exists; otherwise, default(T).
Declaration
public T Value<T>(int[] idx, long? hashVal = null)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | idx | Array of Mat::dims indices. |
System.Nullable<System.Int64> | hashVal | If hashVal is not null, the element hash value is not computed but hashval is taken instead. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |