OpenCV
4.1.2
Open Source Computer Vision
|
The class SparseMat represents multi-dimensional sparse numerical arrays. More...
#include <opencv2/core/mat.hpp>
Classes | |
struct | Hdr |
the sparse matrix header More... | |
struct | Node |
sparse matrix node - element of a hash table More... | |
Public Types | |
enum | { MAGIC_VAL =0x42FD0000, MAX_DIM =32, HASH_SCALE =0x5bd1e995, HASH_BIT =0x80000000 } |
typedef SparseMatConstIterator | const_iterator |
typedef SparseMatIterator | iterator |
Public Member Functions | |
SparseMat () | |
Various SparseMat constructors. More... | |
SparseMat (int dims, const int *_sizes, int _type) | |
SparseMat (const SparseMat &m) | |
SparseMat (const Mat &m) | |
~SparseMat () | |
the destructor More... | |
void | addref () |
manually increments the reference counter to the header. More... | |
void | assignTo (SparseMat &m, int type=-1) const |
int | channels () const |
returns the number of channels More... | |
void | clear () |
sets all the sparse matrix elements to 0, which means clearing the hash table. More... | |
SparseMat | clone () const CV_NODISCARD |
creates full copy of the matrix More... | |
void | convertTo (SparseMat &m, int rtype, double alpha=1) const |
multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type More... | |
void | convertTo (Mat &m, int rtype, double alpha=1, double beta=0) const |
converts sparse matrix to dense n-dim matrix with optional type conversion and scaling. More... | |
void | copyTo (SparseMat &m) const |
copies all the data to the destination matrix. All the previous content of m is erased More... | |
void | copyTo (Mat &m) const |
converts sparse matrix to dense matrix. More... | |
void | create (int dims, const int *_sizes, int _type) |
reallocates sparse matrix. More... | |
int | depth () const |
returns the depth of sparse matrix elements More... | |
int | dims () const |
returns the matrix dimensionality More... | |
size_t | elemSize () const |
converts sparse matrix to the old-style representation; all the elements are copied. More... | |
size_t | elemSize1 () const |
returns elemSize()/channels() More... | |
SparseMatIterator | end () |
returns the sparse matrix iterator at the matrix end More... | |
SparseMatConstIterator | end () const |
returns the read-only sparse matrix iterator at the matrix end More... | |
template<typename _Tp > | |
SparseMatIterator_< _Tp > | end () |
returns the typed sparse matrix iterator at the matrix end More... | |
template<typename _Tp > | |
SparseMatConstIterator_< _Tp > | end () const |
returns the typed read-only sparse matrix iterator at the matrix end More... | |
void | erase (int i0, int i1, size_t *hashval=0) |
erases the specified element (2D case) More... | |
void | erase (int i0, int i1, int i2, size_t *hashval=0) |
erases the specified element (3D case) More... | |
void | erase (const int *idx, size_t *hashval=0) |
erases the specified element (nD case) More... | |
size_t | hash (int i0) const |
computes the element hash value (1D case) More... | |
size_t | hash (int i0, int i1) const |
computes the element hash value (2D case) More... | |
size_t | hash (int i0, int i1, int i2) const |
computes the element hash value (3D case) More... | |
size_t | hash (const int *idx) const |
computes the element hash value (nD case) More... | |
uchar * | newNode (const int *idx, size_t hashval) |
Node * | node (size_t nidx) |
const Node * | node (size_t nidx) const |
size_t | nzcount () const |
returns the number of non-zero elements (=the number of hash table nodes) More... | |
SparseMat & | operator= (const SparseMat &m) |
assignment operator. This is O(1) operation, i.e. no data is copied More... | |
SparseMat & | operator= (const Mat &m) |
equivalent to the corresponding constructor More... | |
void | release () |
void | removeNode (size_t hidx, size_t nidx, size_t previdx) |
void | resizeHashTab (size_t newsize) |
const int * | size () const |
returns the array of sizes, or NULL if the matrix is not allocated More... | |
int | size (int i) const |
returns the size of i-th matrix dimension (or 0) More... | |
int | type () const |
returns type of sparse matrix elements More... | |
template<typename _Tp > | |
_Tp & | value (Node *n) |
returns the value stored in the sparse martix node More... | |
template<typename _Tp > | |
const _Tp & | value (const Node *n) const |
returns the value stored in the sparse martix node More... | |
uchar * | ptr (int i0, bool createMissing, size_t *hashval=0) |
returns pointer to the specified element (1D case) More... | |
uchar * | ptr (int i0, int i1, bool createMissing, size_t *hashval=0) |
returns pointer to the specified element (2D case) More... | |
uchar * | ptr (int i0, int i1, int i2, bool createMissing, size_t *hashval=0) |
returns pointer to the specified element (3D case) More... | |
uchar * | ptr (const int *idx, bool createMissing, size_t *hashval=0) |
returns pointer to the specified element (nD case) More... | |
template<typename _Tp > | |
_Tp & | ref (int i0, size_t *hashval=0) |
returns reference to the specified element (1D case) More... | |
template<typename _Tp > | |
_Tp & | ref (int i0, int i1, size_t *hashval=0) |
returns reference to the specified element (2D case) More... | |
template<typename _Tp > | |
_Tp & | ref (int i0, int i1, int i2, size_t *hashval=0) |
returns reference to the specified element (3D case) More... | |
template<typename _Tp > | |
_Tp & | ref (const int *idx, size_t *hashval=0) |
returns reference to the specified element (nD case) More... | |
template<typename _Tp > | |
_Tp | value (int i0, size_t *hashval=0) const |
returns value of the specified element (1D case) More... | |
template<typename _Tp > | |
_Tp | value (int i0, int i1, size_t *hashval=0) const |
returns value of the specified element (2D case) More... | |
template<typename _Tp > | |
_Tp | value (int i0, int i1, int i2, size_t *hashval=0) const |
returns value of the specified element (3D case) More... | |
template<typename _Tp > | |
_Tp | value (const int *idx, size_t *hashval=0) const |
returns value of the specified element (nD case) More... | |
template<typename _Tp > | |
const _Tp * | find (int i0, size_t *hashval=0) const |
returns pointer to the specified element (1D case) More... | |
template<typename _Tp > | |
const _Tp * | find (int i0, int i1, size_t *hashval=0) const |
returns pointer to the specified element (2D case) More... | |
template<typename _Tp > | |
const _Tp * | find (int i0, int i1, int i2, size_t *hashval=0) const |
returns pointer to the specified element (3D case) More... | |
template<typename _Tp > | |
const _Tp * | find (const int *idx, size_t *hashval=0) const |
returns pointer to the specified element (nD case) More... | |
SparseMatIterator | begin () |
returns the sparse matrix iterator at the matrix beginning More... | |
template<typename _Tp > | |
SparseMatIterator_< _Tp > | begin () |
returns the sparse matrix iterator at the matrix beginning More... | |
SparseMatConstIterator | begin () const |
returns the read-only sparse matrix iterator at the matrix beginning More... | |
template<typename _Tp > | |
SparseMatConstIterator_< _Tp > | begin () const |
returns the read-only sparse matrix iterator at the matrix beginning More... | |
Public Attributes | |
int | flags |
Hdr * | hdr |
The class SparseMat represents multi-dimensional sparse numerical arrays.
Such a sparse array can store elements of any type that Mat can store. Sparse means that only non-zero elements are stored (though, as a result of operations on a sparse matrix, some of its stored elements can actually become 0. It is up to you to detect such elements and delete them using SparseMat::erase ). The non-zero elements are stored in a hash table that grows when it is filled so that the search time is O(1) in average (regardless of whether element is there or not). Elements can be accessed using the following methods:
cv::SparseMat::SparseMat | ( | ) |
Various SparseMat constructors.
cv::SparseMat::SparseMat | ( | int | dims, |
const int * | _sizes, | ||
int | _type | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
dims | Array dimensionality. |
_sizes | Sparce matrix size on all dementions. |
_type | Sparse matrix data type. |
cv::SparseMat::SparseMat | ( | const SparseMat & | m | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
m | Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted to sparse representation. |
|
explicit |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
m | Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted to sparse representation. |
cv::SparseMat::~SparseMat | ( | ) |
the destructor
void cv::SparseMat::addref | ( | ) |
manually increments the reference counter to the header.
void cv::SparseMat::assignTo | ( | SparseMat & | m, |
int | type = -1 |
||
) | const |
SparseMatIterator cv::SparseMat::begin | ( | ) |
returns the sparse matrix iterator at the matrix beginning
return the sparse matrix iterator pointing to the first sparse matrix element
SparseMatIterator_<_Tp> cv::SparseMat::begin | ( | ) |
returns the sparse matrix iterator at the matrix beginning
SparseMatConstIterator cv::SparseMat::begin | ( | ) | const |
returns the read-only sparse matrix iterator at the matrix beginning
SparseMatConstIterator_<_Tp> cv::SparseMat::begin | ( | ) | const |
returns the read-only sparse matrix iterator at the matrix beginning
int cv::SparseMat::channels | ( | ) | const |
returns the number of channels
void cv::SparseMat::clear | ( | ) |
sets all the sparse matrix elements to 0, which means clearing the hash table.
SparseMat cv::SparseMat::clone | ( | ) | const |
creates full copy of the matrix
void cv::SparseMat::convertTo | ( | SparseMat & | m, |
int | rtype, | ||
double | alpha = 1 |
||
) | const |
multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type
void cv::SparseMat::convertTo | ( | Mat & | m, |
int | rtype, | ||
double | alpha = 1 , |
||
double | beta = 0 |
||
) | const |
converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.
[out] | m | - output matrix; if it does not have a proper size or type before the operation, it is reallocated |
[in] | rtype | - desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input. |
[in] | alpha | - optional scale factor |
[in] | beta | - optional delta added to the scaled values |
void cv::SparseMat::copyTo | ( | SparseMat & | m | ) | const |
copies all the data to the destination matrix. All the previous content of m is erased
void cv::SparseMat::copyTo | ( | Mat & | m | ) | const |
converts sparse matrix to dense matrix.
void cv::SparseMat::create | ( | int | dims, |
const int * | _sizes, | ||
int | _type | ||
) |
int cv::SparseMat::depth | ( | ) | const |
returns the depth of sparse matrix elements
int cv::SparseMat::dims | ( | ) | const |
returns the matrix dimensionality
size_t cv::SparseMat::elemSize | ( | ) | const |
converts sparse matrix to the old-style representation; all the elements are copied.
returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements)
size_t cv::SparseMat::elemSize1 | ( | ) | const |
returns elemSize()/channels()
SparseMatIterator cv::SparseMat::end | ( | ) |
returns the sparse matrix iterator at the matrix end
return the sparse matrix iterator pointing to the element following the last sparse matrix element
SparseMatConstIterator cv::SparseMat::end | ( | ) | const |
returns the read-only sparse matrix iterator at the matrix end
SparseMatIterator_<_Tp> cv::SparseMat::end | ( | ) |
returns the typed sparse matrix iterator at the matrix end
SparseMatConstIterator_<_Tp> cv::SparseMat::end | ( | ) | const |
returns the typed read-only sparse matrix iterator at the matrix end
void cv::SparseMat::erase | ( | int | i0, |
int | i1, | ||
size_t * | hashval = 0 |
||
) |
erases the specified element (2D case)
void cv::SparseMat::erase | ( | int | i0, |
int | i1, | ||
int | i2, | ||
size_t * | hashval = 0 |
||
) |
erases the specified element (3D case)
void cv::SparseMat::erase | ( | const int * | idx, |
size_t * | hashval = 0 |
||
) |
erases the specified element (nD case)
const _Tp* cv::SparseMat::find | ( | int | i0, |
size_t * | hashval = 0 |
||
) | const |
returns pointer to the specified element (1D case)
Return pointer to the specified sparse matrix element if it exists
find<_Tp>(i0,...[,hashval])
is equivalent to (_const Tp*)ptr(i0,...false[,hashval])
.
If the specified element does not exist, the methods return NULL.
const _Tp* cv::SparseMat::find | ( | int | i0, |
int | i1, | ||
size_t * | hashval = 0 |
||
) | const |
returns pointer to the specified element (2D case)
const _Tp* cv::SparseMat::find | ( | int | i0, |
int | i1, | ||
int | i2, | ||
size_t * | hashval = 0 |
||
) | const |
returns pointer to the specified element (3D case)
const _Tp* cv::SparseMat::find | ( | const int * | idx, |
size_t * | hashval = 0 |
||
) | const |
returns pointer to the specified element (nD case)
size_t cv::SparseMat::hash | ( | int | i0 | ) | const |
computes the element hash value (1D case)
size_t cv::SparseMat::hash | ( | int | i0, |
int | i1 | ||
) | const |
computes the element hash value (2D case)
size_t cv::SparseMat::hash | ( | int | i0, |
int | i1, | ||
int | i2 | ||
) | const |
computes the element hash value (3D case)
size_t cv::SparseMat::hash | ( | const int * | idx | ) | const |
computes the element hash value (nD case)
uchar* cv::SparseMat::newNode | ( | const int * | idx, |
size_t | hashval | ||
) |
Node* cv::SparseMat::node | ( | size_t | nidx | ) |
const Node* cv::SparseMat::node | ( | size_t | nidx | ) | const |
size_t cv::SparseMat::nzcount | ( | ) | const |
returns the number of non-zero elements (=the number of hash table nodes)
assignment operator. This is O(1) operation, i.e. no data is copied
uchar* cv::SparseMat::ptr | ( | int | i0, |
bool | createMissing, | ||
size_t * | hashval = 0 |
||
) |
returns pointer to the specified element (1D case)
specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case. return pointer to the matrix element.
uchar* cv::SparseMat::ptr | ( | int | i0, |
int | i1, | ||
bool | createMissing, | ||
size_t * | hashval = 0 |
||
) |
returns pointer to the specified element (2D case)
uchar* cv::SparseMat::ptr | ( | int | i0, |
int | i1, | ||
int | i2, | ||
bool | createMissing, | ||
size_t * | hashval = 0 |
||
) |
returns pointer to the specified element (3D case)
uchar* cv::SparseMat::ptr | ( | const int * | idx, |
bool | createMissing, | ||
size_t * | hashval = 0 |
||
) |
returns pointer to the specified element (nD case)
_Tp& cv::SparseMat::ref | ( | int | i0, |
size_t * | hashval = 0 |
||
) |
returns reference to the specified element (1D case)
return read-write reference to the specified sparse matrix element.
ref<_Tp>(i0,...[,hashval])
is equivalent to *(_Tp*)ptr(i0,...,true[,hashval])
. The methods always return a valid reference. If the element did not exist, it is created and initialized with 0.
_Tp& cv::SparseMat::ref | ( | int | i0, |
int | i1, | ||
size_t * | hashval = 0 |
||
) |
returns reference to the specified element (2D case)
_Tp& cv::SparseMat::ref | ( | int | i0, |
int | i1, | ||
int | i2, | ||
size_t * | hashval = 0 |
||
) |
returns reference to the specified element (3D case)
_Tp& cv::SparseMat::ref | ( | const int * | idx, |
size_t * | hashval = 0 |
||
) |
returns reference to the specified element (nD case)
void cv::SparseMat::release | ( | ) |
void cv::SparseMat::removeNode | ( | size_t | hidx, |
size_t | nidx, | ||
size_t | previdx | ||
) |
void cv::SparseMat::resizeHashTab | ( | size_t | newsize | ) |
const int* cv::SparseMat::size | ( | ) | const |
returns the array of sizes, or NULL if the matrix is not allocated
int cv::SparseMat::size | ( | int | i | ) | const |
returns the size of i-th matrix dimension (or 0)
int cv::SparseMat::type | ( | ) | const |
returns type of sparse matrix elements
_Tp cv::SparseMat::value | ( | int | i0, |
size_t * | hashval = 0 |
||
) | const |
returns value of the specified element (1D case)
return value of the specified sparse matrix element.
value<_Tp>(i0,...[,hashval])
is equivalent to
That is, if the element did not exist, the methods return 0.
_Tp cv::SparseMat::value | ( | int | i0, |
int | i1, | ||
size_t * | hashval = 0 |
||
) | const |
returns value of the specified element (2D case)
_Tp cv::SparseMat::value | ( | int | i0, |
int | i1, | ||
int | i2, | ||
size_t * | hashval = 0 |
||
) | const |
returns value of the specified element (3D case)
_Tp cv::SparseMat::value | ( | const int * | idx, |
size_t * | hashval = 0 |
||
) | const |
returns value of the specified element (nD case)
_Tp& cv::SparseMat::value | ( | Node * | n | ) |
returns the value stored in the sparse martix node
const _Tp& cv::SparseMat::value | ( | const Node * | n | ) | const |
returns the value stored in the sparse martix node
int cv::SparseMat::flags |
Hdr* cv::SparseMat::hdr |