Ask Your Question

Revision history [back]

The task is solved using convexHull() function.

image description

vector<vector<Point> > contours_poly(contours.size());
vector<Point> contours_dots;
vector<Point> conv_hull;
Point dot;

for (size_t i = 0; i < contours.size(); i++)
{
    approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
}
for (size_t i = 0; i < contours.size(); i++)
{
    for (size_t j = 0; j < contours[i].size(); j++)
    {
        dot = contours[i][j];
        contours_dots.push_back(dot);
    }
}
convexHull(contours_dots, conv_hull);
contours_poly.push_back(conv_hull);