Ask Your Question

Revision history [back]

Hi @konstunn!

Contours are aligned in opencv as a hierarchy of parent & child contours based on the type of Contour approximation method you choose for detailed explanation refer this wiki.

If you are having a Vector of Points & you want to sort these points you can refer this code:

bool SortbyXaxis(const Point & a, const Point &b) 
{
    return a.x < b.x;
}
bool SortbyYaxis(const Point & a, const Point &b) 
{
    return a.Y < b.Y;
}

vector<Point> Points;
sort( Points.begin(), Points.end(), SortbyYaxis );
sort( Points.begin(), Points.end(), SortbyXaxis );
click to hide/show revision 2
Formated for Punctuation correction.

Hi @konstunn!

Contours are aligned in opencv as a hierarchy of parent & child contours based on the type of Contour approximation method you choose for choose. For detailed explanation refer this wiki.

If you are having a Vector of Points & you want to sort these points you can refer this code:

bool SortbyXaxis(const Point & a, const Point &b) 
{
    return a.x < b.x;
}
bool SortbyYaxis(const Point & a, const Point &b) 
{
    return a.Y < b.Y;
}

vector<Point> Points;
sort( Points.begin(), Points.end(), SortbyYaxis );
sort( Points.begin(), Points.end(), SortbyXaxis );

Hi @konstunn!

Contours are aligned in opencv as a hierarchy of parent & child contours based on the type of Contour approximation method you choose. For detailed explanation refer this wiki.

If you are having a Vector of Points & you want to sort these points you can refer this code:

bool SortbyXaxis(const Point & a, const Point &b) 
{
    return a.x < b.x;
}
bool SortbyYaxis(const Point & a, const Point &b) 
{
    return a.Y < b.Y;
}

vector<Point> Points;
sort( Points.begin(), Points.end(), SortbyYaxis );
sort( Points.begin(), Points.end(), SortbyXaxis );

additionally see also this answer.