1 | initial version |
so, you already found out about contours & boundingRects, great !
now the only thing left is to find the largest one, which is not difficult at all:
double maxArea = 0; // keep track of the largest size
int maxId = -1; // which one.
for (size_t i = 0; i < contours.size(); i++)
{
double area = boundRect[i].width * boundRect[i].height;
if (area > maxArea)
{
maxArea = area;
maxId = i;
}
}
if (maxId != -1)
{
// safe to assume, that contours[maxId] is the larest of them !
}
2 | No.2 Revision |
so, you already found out about contours & boundingRects, great !
now the only thing left is to find the largest one, which is not difficult at all:
double maxArea = 0; // keep track of the largest size
int maxId = -1; // which one.
for (size_t i = 0; i < contours.size(); i++)
{
double area = boundRect[i].width * boundRect[i].height;
if (area > maxArea)
{
maxArea = area;
maxId = i;
}
}
if (maxId != -1)
{
// safe to assume, that contours[maxId] is the larest largest of them !
rectangle(drawing, boundRect[maxId].tl(), boundRect[maxId].br(), Scalar(0,200,0), 2, 8, 0);
}
3 | No.3 Revision |
so, you already found out about contours & boundingRects, great !
now the only thing left is to find the largest one, which is not difficult at all:
double maxArea = 0; // keep track of the largest size
int maxId = -1; // which one.
for (size_t i = 0; i < contours.size(); i++)
{
double area = boundRect[i].width * boundRect[i].height;
if (area > maxArea)
{
maxArea = area;
maxId = i;
}
}
if (maxId != -1)
{
{
// safe to assume, that contours[maxId] is the largest of them !
rectangle(drawing, boundRect[maxId].tl(), boundRect[maxId].br(), Scalar(0,200,0), 2, 8, 0);
}
} // else assume, it did not find any contours at all. can't rule that out !