Table of Contents

Class SparseMat

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Sparse matrix (cv::SparseMat). This type-erased base exposes the structural and metadata operations that do not depend on the element type. For typed element access use SparseMat<T> (e.g. via As<T>()).

public class SparseMat : CvObject, IDisposable
Inheritance
SparseMat
Implements
Derived
Inherited Members

Constructors

SparseMat()

Creates an empty SparseMat.

public SparseMat()

SparseMat(Mat)

Converts a dense cv::Mat to a sparse matrix.

public SparseMat(Mat m)

Parameters

m Mat

cv::Mat object

SparseMat(IEnumerable<int>, MatType)

Constructs an n-dimensional sparse matrix.

public SparseMat(IEnumerable<int> sizes, MatType type)

Parameters

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

type MatType

Array type.

SparseMat(nint)

Creates from a native cv::SparseMat* pointer.

public SparseMat(nint ptr)

Parameters

ptr nint

Methods

AddRef()

Manually increments the reference counter to the header.

public void AddRef()

As<T>()

Returns a typed view of this sparse matrix. The element type must match this matrix's type. The returned matrix shares the data with this one (O(1)).

public SparseMat<T> As<T>() where T : unmanaged

Returns

SparseMat<T>

Type Parameters

T

Element type matching this matrix's Type().

AssignFrom(Mat)

Assignment from a dense matrix (equivalent to the corresponding constructor).

public SparseMat AssignFrom(Mat m)

Parameters

m Mat

Returns

SparseMat

AssignFrom(SparseMat)

Assignment operator. This is an O(1) operation that shares the data.

public SparseMat AssignFrom(SparseMat m)

Parameters

m SparseMat

Returns

SparseMat

AssignTo(SparseMat, MatType?)

public void AssignTo(SparseMat m, MatType? type = null)

Parameters

m SparseMat
type MatType?

Channels()

Returns the number of sparse matrix channels.

public int Channels()

Returns

int

Clear()

Sets all the matrix elements to 0, which means clearing the hash table.

public void Clear()

Clone()

Creates a full copy of the matrix.

public SparseMat Clone()

Returns

SparseMat

ConvertTo(Mat, MatType, double, double)

Converts sparse matrix to dense matrix.

public void ConvertTo(Mat m, MatType rtype, double alpha = 1, double beta = 0)

Parameters

m Mat
rtype MatType
alpha double
beta double

ConvertTo(SparseMat, MatType, double)

Multiplies all the matrix elements by the specified scale factor.

public void ConvertTo(SparseMat m, MatType rtype, double alpha = 1)

Parameters

m SparseMat
rtype MatType
alpha double

CopyTo(Mat)

Converts the sparse matrix to a dense matrix.

public void CopyTo(Mat m)

Parameters

m Mat

CopyTo(SparseMat)

Copies all the data to another sparse matrix.

public void CopyTo(SparseMat m)

Parameters

m SparseMat

Create(MatType, params int[])

Reallocates the sparse matrix.

public void Create(MatType type, params int[] sizes)

Parameters

type MatType
sizes int[]

Depth()

Returns the depth of sparse matrix element.

public int Depth()

Returns

int

Dims()

Returns the matrix dimensionality.

public int Dims()

Returns

int

ElemSize()

Returns the size of each element in bytes.

public int ElemSize()

Returns

int

ElemSize1()

Returns the size of each element channel in bytes.

public int ElemSize1()

Returns

int

FromMat(Mat)

Creates a sparse matrix from a dense cv::Mat.

public static SparseMat FromMat(Mat mat)

Parameters

mat Mat

Returns

SparseMat

NzCount()

Returns the number of non-zero elements (the number of hash table nodes).

public long NzCount()

Returns

long

Release()

Releases the resources.

public void Release()

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

dim int

Returns

int

ToMat()

Converts this sparse matrix to a new dense Mat of the same type.

public Mat ToMat()

Returns

Mat

ToString()

Returns a string that represents this SparseMat.

public override string ToString()

Returns

string

Type()

Returns the type of sparse matrix element.

public MatType Type()

Returns

MatType