I am trying to count all white pixels in an OpenCV binary image. My current code is as follows:
whitePixels = 0;
for (int i = 0; i < height; ++i)
for (int j = 0; j < width; ++j)
if (binary.at<int>(i, j) != 0)
++whitePixels;
However, after profiling with gprof, I found this to be a very slow piece of code and a big bottleneck in the program.
Is there a way that calculates the same value faster?
source
share