Class SparseMat<T>
- Namespace
- OpenCvSharp
- Assembly
- OpenCvSharp.dll
Strongly-typed sparse matrix. T determines the element type, so element
access needs no per-call type argument and no runtime type checks: reading an absent element
returns default without creating it; assigning through the indexer creates it.
public sealed class SparseMat<T> : SparseMat, IDisposable where T : unmanaged
Type Parameters
- Inheritance
-
SparseMat<T>
- Implements
- Inherited Members
Constructors
- SparseMat(params int[])
Constructs an n-dimensional sparse matrix of the given shape.
Properties
- this[int, int]
Gets or sets the element at the given 2-D index. Reading an absent element returns
default(without creating it); assigning creates the element.
- this[int, int, int]
Gets or sets the element at the given 3-D index. Reading an absent element returns
default(without creating it); assigning creates the element.
- this[ReadOnlySpan<int>]
Gets or sets the element at the given n-D index. Reading an absent element returns
default(without creating it); assigning creates the element.
Methods
- Clone()
Creates a full (deep) copy of the matrix.
- Contains(ReadOnlySpan<int>)
Returns whether an element is stored (non-zero) at the given index.
- EnumerateNonZero()
Enumerates every stored (non-zero) element together with its index, mirroring cv::SparseMatConstIterator. This visits only the stored elements, not the full dense index space.
- FromMat(Mat)
Creates a typed sparse matrix from a dense Mat. The Mat type must match
T.
- GetValueRef(ReadOnlySpan<int>)
Returns a reference to the element at the given index, creating it (zero-initialized) if it does not exist. Useful for in-place updates such as accumulation (
sm.GetValueRef(i, j)++), which performs a single hash lookup.
- Remove(ReadOnlySpan<int>)
Removes the stored element at the given index. Returns false if it was not stored.
- TryGetValue(ReadOnlySpan<int>, out T)
Gets the element at the given index if it is stored, without creating it.