title: Count 'white' pixels in opencv binary image (efficiently)
body: <p>I am trying to count all the white pixels in an OpenCV binary image. My current code is as follows:</p>
  
  <pre><code>  whitePixels = 0;
    for (int i = 0; i &lt; height; ++i)
      for (int j = 0; j &lt; width; ++j)
        if (binary.at&lt;int&gt;(i, j) != 0)
          ++whitePixels;
  </code></pre>
  
  <p>However, after profiling with gprof I've found that this is a very slow piece of code, and a large bottleneck in the program. </p>
  
  <p>Is there a method which can compute the same value faster?</p>