1 | initial version |
For dividing the image horizontally into 2 equal parts and counting the white pixels in both parts, you shall do
cv::Rect topROI(0, 0, imageInit.cols, imageInit.rows / 2); // here you should treat the case of odd number of rows
cv::Rect bottomROI(0, imageInit.cols / 2 + 1, imageInit.cols, imageInit.rows);
int whitePixelsTop = cv::countNonZero(imageInit(topROI));
int whitePixelsBottom = cv::countNonZero(imageInit(bottomROI));
2 | No.2 Revision |
For dividing the image horizontally into 2 equal parts and counting the white pixels in both parts, you shall do
// imageInit should be a single-channel Mat
cv::Rect topROI(0, topROI( 0, 0, imageInit.cols, imageInit.rows / 2); // here you should treat the case of odd number of rows
2 );
cv::Rect bottomROI(0, imageInit.cols / 2 + 1, bottomROI( 0, topROI.height, imageInit.cols, imageInit.rows);
imageInit.rows - topROI.height );
int whitePixelsTop = cv::countNonZero(imageInit(topROI));
cv::countNonZero( imageInit(topROI) );
int whitePixelsBottom = cv::countNonZero(imageInit(bottomROI));
cv::countNonZero( imageInit(bottomROI) );