Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you are able to find ROI, the remains problem is counting the Read-pixels inside ROI rectangle.

You could do it by enumerate every pixels in the images then count (please do check whether pixels is inside ROI yourself):

const int channels = I.channels();
count = 0; // count is the number of Red pixels
switch(channels)
{
case 1:
    {
        MatIterator_<uchar> it, end;
        for( it = I.begin<uchar>(), end = I.end<uchar>(); it != end; ++it)
            if (*it == 0) // black
            {
                  count++;
            }
        break;
    }
case 3:
    {
        MatIterator_<Vec3b> it, end;
        for( it = I.begin<Vec3b>(), end = I.end<Vec3b>(); it != end; ++it)
        {
            if ((*it[2])==255) // Red
            {
                   count++;
            }
        }
    }
}