OpenCV - Counting number of black pixels

c, image-processing, opencv, optimization

Solution

I believe the number of zero pixels could be seen as:

int TotalNumberOfPixels = width * height;
int ZeroPixels = TotalNumberOfPixels - cvCountNonZero(cv_image);

Problem

I have a binary image. Within a certain region of interest, I need to count the number of black pixels. There is always the way of looping through the pixels and counting them, but I'm looking for a more efficient method as I need to do it real-time. I found a way to count the number of nonzero pixels(using cvCountNonZero()). Is there any such equivalent function for counting zero pixels (there doesn't seem to be as far as I've seen)? If not, what is the most efficient way to count the black pixels?

Original source

Related problems