#include <stdio.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
void main()
{
int size\[\] = { 10,10 };
cv::SparseMat sm(2, size, CV_32F);
for (int i = 0; i < 10; i++)
{
int idx2;
idx0 = size0 * rand();
idx1 = size1 * rand();
//Fill the array
sm.ref<float>(idx) += 1.0f;
//Print out the nonzero elements
//
}
cv::SparseMatConstIterator_<float>it = sm.begin<float>();
cv::SparseMatConstIterator_<float>it_end = sm.end<float>();
for (; it != it_end; ++it)
{
const cv::SparseMat::Node* node = it.node();
printf("(%3d,%3d)%f\n", node->idx0, node->idx1, *it);
}
return;
}
结果打印:
