检测阈值区域

Detecting threshold area(s)

我有阈值图像:

我想知道,我可以检测到 "white zones" 并在它们周围绘制矩形(也需要保存数据)
或者我可以画平行六面体(多边形)并且里面的 "say" 区域是白色的吗?
谢谢

因此,为了检测白色区域,只需获取图像的轮廓即可。这可以通过以下方式完成:

vector<vector<Point>>contours;
vector<Vec4i> hierarchy;
findContours(blackWhiteImage,
    contours,
    hierarchy,
    CV_RETR_TREE,
    CV_CHAIN_APPROX_SIMPLE,
    Point(0,0));

然后,您可以生成对提取的每个轮廓建模的近似边界框:

vector<vector<Point> > contours_poly( contours.size() );
vector<Rect> boundRect( contours.size() );
for( int i = 0; i < contours.size(); i++ ){
   approxPolyDP( Mat(contours[i]),
       contours_poly[i],
       3,
       true );
       //3 is epsilon tuning param for bias-variance trade off
       //true denotes contours are closed

   boundRect[i] = boundingRect( Mat(contours_poly[i]) );
}

一旦完成,您就可以访问 boundingRect 数组中的 boundingRect 对象,就像访问任何其他数组一样。

没有近似值的 EmguCV (C#) 模拟代码:

VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
Mat hierarchy;

CvInvoke.FindContours(binMat, contours, hierarchy, RetrType.External, ChainApproxMethod.ChainApproxSimple);

for (int i = 0; i < contours.Size; ++i)
{
    if (CvInvoke.ContourArea(contours[i]) > 8)
    {
        Rectangle rc = CvInvoke.BoundingRectangle(contours[i]);
        CvInvoke.Rectangle(srcMat, rc, new MCvScalar(0, 0, 255));
    }
}