Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

sum() returns a Scalar with the sum of all pixels per channel

so, for a 3channel img (think a color image),

Scalar s = sum(img);
// s[0] is the sum of the 1st channel (B probably)
// s[1] is the sum of the 2nd channel (G probably)
// s[2] ...

in your case, the Mat only has one channel, so double s = sum(mat)[0] is the way to access it.