Calculate object area inside ROI in OpenCV
<p>I want to calculate area of detected object (that blue marker I used) inside actual ROI. I mean one of those two rectangles that are my Regions Of Interest in Threshold image (which is black and white).</p>

<p><strong>How to calculate area of object</strong> (I think - sum of "recognized" cluster of pixels, which are white color) <strong>inside ROI?</strong></p>

<p><a href="https://i.stack.imgur.com/fhtub.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fhtub.png" alt="enter image description here"></a></p>

<p>I just want to consider only those pixels that are inside of concrete ROI (in below example - the left one). So all pixels beyond left ROI will not be taken into calculations.</p>

<p><a href="https://i.stack.imgur.com/7xdTS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7xdTS.png" alt="enter image description here"></a></p>

<p>ROIs are created like this: </p>

<pre><code>rectangle( imgOriginal, Point( 20, 100 ), Point( 170, 250), Scalar( 0, 0, 255 ), +5, 4 );
rectangle( imgThresholded, Point( 20, 100 ), Point( 170, 250), Scalar( 255, 255, 255 ), +5, 4 );
rectangle( imgOriginal, Point( 450, 100 ), Point( 600, 250), Scalar( 0, 0, 255 ), +5, 4 );
rectangle( imgThresholded, Point( 450, 100 ), Point( 600, 250), Scalar( 255, 255, 255 ), +5, 4 );
</code></pre>