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;

}

结果打印:

相关推荐
在钱塘江25 分钟前
LangGraph构建Ai智能体-12-高级RAG之自适应RAG
人工智能·python
聚客AI30 分钟前
🚀碾压传统方案!vLLM与TGI/TensorRT-LLM性能实测对比
人工智能·llm·掘金·日新计划
m0_6038887134 分钟前
LLaMA-Adapter V2 Parameter-Efficient Visual Instruction Model
人工智能·深度学习·ai·llama·论文速览
Elastic 中国社区官方博客39 分钟前
超越相似名称:Elasticsearch semantic text 如何在简洁、高效、集成方面超越 OpenSearch semantic 字段
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
在钱塘江43 分钟前
LangGraph构建Ai智能体-12-高级RAG之纠错式RAG
人工智能·python
居然JuRan1 小时前
大模型微调面试题全解析
人工智能
终端域名1 小时前
建设有人文温度的智能社会:规划与实施路径
人工智能
机器之心2 小时前
港大联手月之暗面等开源OpenCUA:人人可造专属电脑智能体
人工智能·openai
盼小辉丶2 小时前
PyTorch生成式人工智能——基于Transformer实现文本转语音
人工智能·pytorch·transformer
mit6.8243 小时前
[AI React Web]`意图识别`引擎 | `上下文选择算法` | `url内容抓取` | 截图捕获
前端·人工智能·react.js