I think that’s how countNonZeroInRegion works:
countNonZeroInRegion(int x, int y, int w, int h)
you pass in the x,y,w and h of the region of pixels you’d like to count (very useful for creating region based triggers, etc).
for example, if you have a 320x240 image, but you only care about top, left quadrant of the image you could day:
int nWhitePixelsTL = countNonZeroInRegion(0,0,160,120);
and the bottom right quadrant, would be:
int nWhitePixelsBR = countNonZeroInRegion(160,120,160,120);
ROI is part of the iplImage struct - ROI = region of interest. many operations take the ROI into account…
“specifies image region to be processed”
for most of what we have written, with the grayscalImage class, etc, we process the whole image, but there are times when it makes sense to process a sub image. in that case, you can get and set the ROI, then return it back to normal (ROI is a state change, so if you change it, all other oprations will use that new ROI, so important to set it back).
there are functions to get and set the ROI, such as:
void cvSetImageROI(IplImage* image, CvRect rect);
void cvResetImageROI(IplImage* image);
vRect cvGetImageROI(const IplImage* image);
that’s what we do w/ countNonZeroInRegion –
// do something !!
cvResetImageROI( cvImage );
hope that helps!!!