Opencv 8 (打印一个稀疏矩阵中的所有非0元素)

#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 idx[2];
        idx[0] = size[0] * rand();
        idx[1] = size[1] * 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->idx[0], node->idx[1], *it);
    }
    return;
}

结果打印:

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-24 06:38:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-24 06:38:05       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-24 06:38:05       82 阅读
  4. Python语言-面向对象

    2023-12-24 06:38:05       91 阅读

热门阅读

  1. facebook广告投放对落地页的要求

    2023-12-24 06:38:05       66 阅读
  2. POP3协议详解

    2023-12-24 06:38:05       53 阅读
  3. 说说对React refs 的理解?应用场景?

    2023-12-24 06:38:05       72 阅读
  4. 【Unity 摄像机组件】Camera场景摄像机的认识

    2023-12-24 06:38:05       56 阅读
  5. Codeforces Round 916 (Div. 3)(补题)——A---E

    2023-12-24 06:38:05       38 阅读
  6. 如何在Spring Boot中优雅地进行参数校验

    2023-12-24 06:38:05       48 阅读