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中矩阵中的元素总和?


- XML Schema 到 C++ 类 2022-01-01
- 将函数的返回值分配给引用 C++? 2022-01-01
- 如何提取 __VA_ARGS__? 2022-01-01
- 从父 CMakeLists.txt 覆盖 CMake 中的默认选项(...)值 2021-01-01
- 哪个更快:if (bool) 或 if(int)? 2022-01-01
- 将 hdc 内容复制到位图 2022-09-04
- GDB 不显示函数名 2022-01-01
- DoEvents 等效于 C++? 2021-01-01
- OpenGL 对象的 RAII 包装器 2021-01-01
- 使用 __stdcall & 调用 DLLVS2013 中的 GetProcAddress() 2021-01-01