Opencv SparseMat 介绍
Example | Description |
---|---|
cv::SparseMat sm; | Create a sparse matrix without initialization |
cv::SparseMat sm( 3, sz, CV_32F ); | Create a three-dimensional sparse matrix with dimensions given by the array sz of type float |
cv::SparseMat sm( sm0 ); | Create a new sparse matrix that is a copy of the existing sparse matrix sm0 |
cv::SparseMat( m0, try1d ); | Create a sparse matrix from an existing dense matrix m0; if the bool try1d is true, convert m0 to a one-dimensional sparse matrix if the dense matrix was n × 1 or 1 × n |
cv::SparseMat( &old_sparse_mat ); | Create a new sparse matrix from a pointer to a pre–version 2.1 C-style sparse matrix of type CvSparseMat |
CvSparseMat* old_sm = (cv::SparseMat*) sm; | Cast operator creates a pointer to a pre–version 2.1 C-style sparse matrix; that CvSparseMat object is created and all data is copied into it, and then its pointer is returned |
size_t n = sm.nzcount(); | Return the number of nonzero elements in sm |
size_t h = sm.hash( i0 ); size_t h = sm.hash( i0, i1 ); size_t h = sm.hash( i0, i1, i2 ); size_t h = sm.hash( idx ); | Return the hash value for element i0 in a one-dimensional sparse matrix; i0, i1 in a two-dimensional sparse matrix; i0, i1, i2 in a threedimensional sparse matrix; or the element indicated by the array of integers idx in an n-dimensional sparse matrix |
sm.ref<float>( i0 ) = f0; sm.ref<float>( i0, i1 ) = f0; sm.ref<float>( i0, i1, i2 ) = f0; sm.ref<float>( idx ) = f0; | Assign the value f0 to element i0 in a one-dimensional sparse matrix; i0, i1 in a two-dimensional sparse matrix; i0, i1, i2 in a threedimensional sparse matrix; or the element indicated by the array of integers idx in an n-dimensional sparse matrix |
f0 = sm.value<float>( i0 ); f0 = sm.value<float>( i0, i1 ); f0 = sm.value<float>( i0, i1, i2 ); f0 = sm.value<float>( idx ); | Assign the value to f0 from element i0 in a one-dimensional sparse matrix; i0, i1 in a two-dimensional sparse matrix; i0, i1, i2 in a threedimensional sparse matrix; or the element indicated by the array of integers idx in an n-dimensional sparse matrix |
p0 = sm.find<float>( i0 ); p0 = sm.find<float>( i0, i1 ); p0 = sm.find<float>( i0, i1, i2 ); p0 = sm.find<float>( idx ); | Assign to p0 the address of element i0 in a one-dimensional sparse matrix; i0, i1 in a two-dimensional sparse matrix; i0, i1, i2 in a threedimensional sparse matrix; or the element indicated by the array of integers idx in an n-dimensional sparse matrix |
sm.erase( i0, i1, &hashval ); sm.erase( i0, i1, i2, &hashval ); sm.erase( idx, &hashval ); | Remove the element at (i0, i1) in a two-dimensional sparse matrix; at (i0, i1, i2) in a three-dimensional sparse matrix; or the element indicated by the array of integers idx in an n-dimensional sparse matrix. If hashval is not NULL, use the provided value instead of computing it |
cv::SparseMatIterator<float> it = sm.begin<float>(); | Create a sparse matrix iterator it and point it at the first value of the floating-point array sm |
cv::SparseMatIterator<uchar> it_end = sm.end<uchar>(); | Create a sparse matrix iterator it_end and initialize it to the value succeeding the final value in the byte array sm |