1 Star 0 Fork 0

Summer/Learning-OpenCV-3_examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example_04-04.cpp 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
Gary Bradski 提交于 2017-06-22 23:09 . hooked up call to help
//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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Summer2474/Learning-OpenCV-3_examples.git
git@gitee.com:Summer2474/Learning-OpenCV-3_examples.git
Summer2474
Learning-OpenCV-3_examples
Learning-OpenCV-3_examples
master

搜索帮助