代码拉取完成,页面将自动刷新
//Example 4-4. A better way to print a matrix
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
// A better way to print a sparse matrix
//
template <class T> void print_matrix( const cv::SparseMat_<T>* sm ) {
cv::SparseMatConstIterator_<T> it = sm->begin();
cv::SparseMatConstIterator_<T> it_end = sm->end();
for(; it != it_end; ++it) {
const typename cv::SparseMat_<T>::Node* node = it.node();
cout <<"( " <<node->idx[0] <<", " <<node->idx[1]
<<" ) = " <<*it <<endl;
}
}
void calling_function1( void ) {
int ndim = 2;
int size[] = {4,4};
cv::SparseMat_<float> sm( ndim, size );
// Create a sparse matrix with a few nonzero elements
//
for( int i=0; i<4; i++ ) { // Fill the array
int idx[2];
idx[0] = size[0] * rand();
idx[1] = size[1] * rand();
sm.ref( idx ) += 1.0f;
}
print_matrix<float>( &sm );
}
void calling_function2( void ) {
int ndim = 2;
int size[] = {4,4};
cv::SparseMat sm( ndim, size, CV_32F );
// Create a sparse matrix with a few nonzero elements
//
for( int i=0; i<4; i++ ) { // Fill the array
int idx[2];
idx[0] = size[0] * rand();
idx[1] = size[1] * rand();
sm.ref<float>( idx ) += 1.0f;
}
print_matrix<float>( (cv::SparseMat_<float>*) &sm );
}
void help(char** argv) {
cout << "\nExample 4-4, a better way to print out a sparse matrix"
<< "\n Demonstrates printing of two different sparse matrices"
<< "\nCall:"
<< argv[0]
<< endl;
}
int main( int argc, char** argv ) {
help(argv);
cout <<"Case 1:" <<endl;
calling_function1();
cout <<endl;
cout <<"Case 2:" <<endl;
calling_function2();
cout <<endl;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。