 <p>I placed this as an edit in Alex's answer, it did not get reviewed though so I'll post it here, as it is useful information imho.</p> <p>You can also pass a vector of Points, makes it easier to do something with them afterwards:</p> <pre><code>std::vector&lt;cv::Point2i&gt; locations; // output, locations of non-zero pixels cv::findNonZero(binaryImage, locations); </code></pre> <p>One note for the <code>cv::findNonZero</code> function in general: if <code>binaryImage</code> contains zero non-zero elements, it will throw because it tries to allocate '1 x n' memory, where n is <code>cv::countNonZero</code>, and n will obviously be 0 then. I circumvent that by manually calling <code>cv::countNonZero</code> beforehand but I don't really like that solution that much.</p>