how to add each pixel of mat in android
hi, how can i add each pixel of a matrix in a loop in android
below is my c++ code :
for(int x=0;x<=4;x++)
{
for(int y=0;y<=4;y++)
{
sum1=sum1+ block.at<uchar>(x, y); // Addition of all elements
sum2=sum2+block.at<uchar>(x,y)*block.at<uchar>(x,y); //Addition of all element square
}
}
where block is a 5x5 mat
http://stackoverflow.com/questions/12394364/opencv-for-android-access-elements-of-mat
Have you seen cv::mean or cv::sum and cv::meanstddev?
i want to add each element of mat variable without having any loop. how is it possible.
http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#sum This of course only works if you want the sum. Since you also calculated the square in your example, you need to have a loop. The java version seems to be this: http://docs.opencv.org/java/2.4.2/org/opencv/core/Core.html#sumElems%28org.opencv.core.Mat%29
sum and sumElems returns scalar value. i want integer value to be returned. i am not able to get integer value.
sum1 = (int) Core.sumElems(block).val[0]; sum2 = (int) Core.sumElems(block.mul(block)).val[0];