Table of Contents

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

m Mat

cv::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

sizes IEnumerable<int>

Array of integers specifying an n-dimensional array shape.

type MatType

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(nint)

Creates from native cv::SparseMat* pointer

public SparseMat(nint ptr)

Parameters

ptr nint

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

m Mat

Returns

SparseMat

AssignFrom(SparseMat)

Assignment operator. This is O(1) operation, i.e. no data is copied

public SparseMat AssignFrom(SparseMat m)

Parameters

m SparseMat

Returns

SparseMat

AssignTo(SparseMat, MatType?)

not used now

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 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

SparseMat

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

m Mat
rtype MatType

The output matrix data type. When it is =-1, the output array will have the same data type as (*this)

alpha double

The scale factor

beta double

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

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

Parameters

m SparseMat
rtype MatType
alpha double

CopyTo(Mat)

converts sparse matrix to dense matrix.

public void CopyTo(Mat m)

Parameters

m Mat

CopyTo(SparseMat)

copies all the data to the destination matrix. All the previous content of m is erased.

public void CopyTo(SparseMat m)

Parameters

m SparseMat

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

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

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

int

ElemSize1()

returns elemSize()/channels()

public int ElemSize1()

Returns

int

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index along the dimension 2

hashVal long?

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

hashVal long?

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

i0 int

Index along the dimension 0

hashVal long?

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

idx int[]

Array of Mat::dims indices.

hashVal long?

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

mat Mat

Returns

SparseMat

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

SparseMat.Indexer<T>

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index along the dimension 2

hashVal long?

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

hashVal long?

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

i0 int

Index along the dimension 0

hashVal long?

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

idx int[]

Array of Mat::dims indices.

hashVal long?

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

i0 int

Index along the dimension 0

Returns

long

Hash(int, int)

Computes the element hash value (2D case)

public long Hash(int i0, int i1)

Parameters

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

Returns

long

Hash(int, int, int)

Computes the element hash value (3D case)

public long Hash(int i0, int i1, int i2)

Parameters

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index along the dimension 2

Returns

long

Hash(params int[])

Computes the element hash value (nD case)

public long Hash(params int[] idx)

Parameters

idx int[]

Array of Mat::dims indices.

Returns

long

NzCount()

returns the number of non-zero elements (=the number of hash table nodes)

public long NzCount()

Returns

long

Ptr(int, bool, long?)

Low-level element-access function.

public nint Ptr(int i0, bool createMissing, long? hashVal = null)

Parameters

i0 int

Index along the dimension 0

createMissing bool

Create new element with 0 value if it does not exist in SparseMat.

hashVal long?

If hashVal is not null, the element hash value is not computed but hashval is taken instead.

Returns

nint

Ptr(int, int, bool, long?)

Low-level element-access function.

public nint Ptr(int i0, int i1, bool createMissing, long? hashVal = null)

Parameters

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

createMissing bool

Create new element with 0 value if it does not exist in SparseMat.

hashVal long?

If hashVal is not null, the element hash value is not computed but hashval is taken instead.

Returns

nint

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index along the dimension 2

createMissing bool

Create new element with 0 value if it does not exist in SparseMat.

hashVal long?

If hashVal is not null, the element hash value is not computed but hashval is taken instead.

Returns

nint

Ptr(int[], bool, long?)

Low-level element-access function.

public nint Ptr(int[] idx, bool createMissing, long? hashVal = null)

Parameters

idx int[]

Array of Mat::dims indices.

createMissing bool

Create new element with 0 value if it does not exist in SparseMat.

hashVal long?

If hashVal is not null, the element hash value is not computed but hashval is taken instead.

Returns

nint

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

SparseMat.Indexer<T>

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index along the dimension 2

value T
hashVal long?

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

value T
hashVal long?

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

i0 int

Index along the dimension 0

value T
hashVal long?

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

idx int[]

Array of Mat::dims indices.

value T
hashVal long?

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

dim int

Returns

int

ToString()

Returns a string that represents this Mat.

public override string ToString()

Returns

string

Type()

Returns the type of sparse matrix element.

public MatType Type()

Returns

MatType

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

i2 int

Index along the dimension 2

hashVal long?

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

i0 int

Index along the dimension 0

i1 int

Index along the dimension 1

hashVal long?

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

i0 int

Index along the dimension 0

hashVal long?

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

idx int[]

Array of Mat::dims indices.

hashVal long?

If hashVal is not null, the element hash value is not computed but hashval is taken instead.

Returns

T

Type Parameters

T