Sum of elements in a matrix in OpenCV?(OpenCV中矩阵中的元素总和?)
问题描述
我需要对矩阵中的所有元素求和.我使用了函数
I need to sum all the elements in a matrix. I used the function
sum(sum(A));
在matlab中.其中 A
是一个大小为 300*360 的矩阵.我想在 OpenCV 中实现相同的功能.我用过这样的东西.
in matlab. Where A
is a matrix of size 300*360.
I want to implement the same function in OpenCV. I used something like this.
double s=cv::sum(cv::sum(A));
但显示无法将标量转换为双精度的错误.如何解决这个问题?
But there is error showing cannot convert scalar to double. How to fix this problem?
推荐答案
与 Matlab 不同,在 opencv 中,cv::sum(A)
沿所有维度求和并返回单个数字(标量)等于Matlab的sum(sum(A))
.
所以,你需要的是
Unlike Matlab, in opencv, cv::sum(A)
sums along ALL dimensions and returns a single number (scalar) that is equal to Matlab's sum(sum(A))
.
So, what you need is
double s = cv::sum(A)[0];
这篇关于OpenCV中矩阵中的元素总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:OpenCV中矩阵中的元素总和?


基础教程推荐
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 设计字符串本地化的最佳方法 2022-01-01