First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered Aug 15 '13

Hansg91 gravatar image

Wouldn't this work?

int count_black = cv::countNonZero(mask == 0);
int count_white = cv::countNonZero(mask == 255);
click to hide/show revision 2
Corrected code

Wouldn't this work?

cv::Mat masked;
image.copyTo(masked, mask);
int count_black = cv::countNonZero(mask cv::countNonZero(masked == 0);
int count_white = cv::countNonZero(mask cv::countNonZero(masked == 255);