With the following code i detect all squares in a gray scale image:
for (;contours != null; contours = contours.HNext)
{
var approxContour = contours.ApproxPoly(contours.Perimeter * 0.05,
contours.Storage);
var rect = approxContour.GetMinAreaRect();
if (IsSquare(rect, rect.size.Height * 0.1f))
boxes.Add(rect);
}
I’m looking for a way to filter the squares based by their color. E.g. I want to remove all squares with an average gray value less then 128.
Which OpenCv function do I have to use?
You have to use ROIs and GetAverage():