Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If image is RGB try cv2.split to split into a single-channel array, and then count non-zero pixels on Blue channel.

cv2.split()

If image is RGB try cv2.split to I do not know how things work in python, but in c++ you can do the following

cv::Mat bgrImage = cv::imread("test.jpg");
std::vector<cv::Mat> bgrChannels;

cv::split(bgrImage, bgrChannels);  // split multi-channels into a single-channel array, and then single-channel
int blue = cv::countNonZero(bgrChannels[0]) // count the non-zero pixels on Blue channel.

channel

cv::split wrap for python cv2.split()