// 寻找最大连通域
double maxArea = 0;
vector<Point> maxContour;
for(size_t i = 0; i < contours.size(); i++)
{
double area = contourArea(contours[i]);
if (area > maxArea)
{
maxArea = area;
maxContour = contours[i];
}
}
// 将轮廓转为矩形框
Rect maxRect = boundingRect(maxContour);
for (size_t i = 0; i < contours.size(); i++)
{
Rect r = boundingRect(contours[i]);
rectangle(resImg, r, Scalar(255));
}
namedWindow("all regions",0);
imshow("all regions", resImg) ;