Building contours from points
Hello !
One of my algorithms constructs points which should represent a contour. My problem with these points is the order. There is no reason these points have the correct connection order in order to be able to build a contour (for example, passing these to cv::drawContours will result in a mess...).
How should I order these points to satisfy the contour definition of OpenCV ? Is it even possible ?
Thanks !
Can you post some code and examples?
I can't post any code (I am not allowed to...), but I'll try to give you an example. Let's say you have found a contour (with cv::findContours for example). If you shuffle the points in the contour, there is no more reason for it to be a valid contour as the connection order (ie the line segment) is important to draw this contour.
My goal would be to restore the order of the connections.
Hoping this is clearer :)
have you tried sort functions on the vector of points?
Hey, you should set a rule for points to make up a contour, like: it is a possibly convex, since a set of points can get many valid contours without crossed line.