Sum of elements in a matrix in OpenCV?
c++, computer-vision, image-processing, matlab, opencv
Solution
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];
Problem
I need to sum all the elements in a matrix. I used the function ``` sum(sum(A)); ``` 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?