title: Ordered list of points along polylines/curves on an image
body: <p>I have images with some combination of polylines/polycurves. My aim is to recover an ordered list of points along these polylines/polycurves.</p>
  <p>Using opencv connectedComponents I can isolate each of these polylines/curves in the image, and then I tried to get an ordered sequence of points with these steps:</p>
  <pre><code>    num_labels, labels_im = cv2.connectedComponents(input_image)     
      ske = skimage.morphology.skeletonize(labels_im==1)
      x,y =np.where(ske)
      cnt = np.vstack([x,y]).T.reshape(-1, 1, 2)        
      recovered_points = cv2.approxPolyDP(cnt, 100, False) 
  </code></pre>
  <p>However, the points in recovered_points don't follow along the original polyline, they are points on the original polyline but in raster order, from let to right, bottom to top, and that's not what I want. Below you can see the input_image(original image), the skeleton image, and the recovered_points points (notice they came out rotated).
  <a href="https://i.stack.imgur.com/XRQ38.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XRQ38.png" alt="enter image description here" /></a></p>
  <p>I have also tried to use findContours on the connected components of the input_image and then approxPolyDP on the contours, but these are contours around the original polylines, so the recovered_points go along the polyline on one side and the comeback on the other and close on the first point, which is neither what I want. See image of the extracted contour below.</p>
  <p><a href="https://i.stack.imgur.com/oyvs9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oyvs9.png" alt="enter image description here" /></a></p>
  <p>Is there anyway in opencv or scikit-image or other library to recover the ordered points along the original polylines/curves?</p>