int count_white=0; int count_black=0;
for (int y = 0; y < image.rows; y++) { for (int x = 0; x < image.cols; x++) { if (image.at<cv::vec3b>(y, x) == cv::Vec3b(255, 255, 255)) { count_white++; } else if (image.at<cv::vec3b>(y, x) == cv::Vec3b(0, 0, 0)) { count_black++; } } }