Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: Getting the total of Mat values

Tags:

c++

opencv

Is there some openCV function that I can pass in a cv::Mat and get the sum of all values in them?

For example: int cvSumFoo(Mat &srcMat); I'm expecting an int to come back

I create it like this:

srcMat= new Mat(rows, cols, CV_8U);

I would like to avoid creating my own loop if at all possible.

like image 618
roboto1986 Avatar asked Apr 14 '12 18:04

roboto1986


People also ask

What is Vec3b?

Vec3b is the abbreviation for "vector with 3 byte entries" Here those byte entries are unsigned char values to represent values between 0 .. 255. Each byte typically represents the intensity of a single color channel, so on default, Vec3b is a single RGB (or better BGR) pixel.

What is CV_32F?

CV_32F : 4-byte floating point ( float ).

What is CV_64F?

That is, image of type CV_64FC1 is simple grayscale image and has only 1 channel: image[i, j] = 0.5. while image of type CV_64FC3 is colored image with 3 channels: image[i, j] = (0.5, 0.3, 0.7) (in C++ you can check individual pixels as image.at<double>(i, j) ) CV_64F is the same as CV_64FC1 .

What is scalar OpenCV?

ScalarRepresents a 4-element vector. The type Scalar is widely used in OpenCV for passing pixel values. In this tutorial, we will use it extensively to represent BGR color values (3 parameters). It is not necessary to define the last argument if it is not going to be used.


1 Answers

The function 'sum' "calculates and returns the sum of array elements, independently for each channel."

You can find the information here: http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#sum

like image 62
dennisg Avatar answered Oct 15 '22 17:10

dennisg