# Contour left of right?

Is there any method on earth that based on these contours, I know that the A contour is on the right of B contour? or vise versa as in the picture? I had been playing with the centroids and coordinate and it does not make sense so far from the result.

There is an idea that I think which is to draw a line base on the centroid at 45 degree toward (0,0) for both centroid and look at the y value crossing.

The question is how can I draw a line from a given centroid at 45 degree and manage to get the crossing point on Y axis. If looking at the first picture, it will not cross Y axis. AM I right? So mybe my idea is not working too.

edit retag close merge delete

1

Your idea seems too complicated. It is easy to find the most left, right, top and bottom points of a given contour. Once you have retrieved them, you can apply rules to order your contours with sort() function. Check this post

( 2015-10-22 05:44:33 -0500 )edit

i think this may be a clue.check deg value

   Point2f a ;
Point2f b ;
double deg = atan((b.y-a.y)/(b.x-a.x)) * 180 / PI;

( 2015-10-22 06:02:19 -0500 )edit
1

First you need to define the labels of the contours, like B the small one and A the big one (like in your image), this you can get by contourArea, or using arcLength, then you need to sort the contours from left to right, and here you need to define what left means (based on the centroid, base on the x or y coordinates of its points, or any other criteria)

( 2015-10-22 07:17:03 -0500 )edit

Sort by ยป oldest newest most voted

OK noted ...

more

Official site

GitHub

Wiki

Documentation