title: Extract well ordered xy coordinates of OpenCV's Canny Edge Detection in python
body: <p>I have a polygon like <a href="http://i.stack.imgur.com/m7Muj.png" rel="nofollow">this</a> and I'd like to get xy coordinates of the boundary of this polygon.</p>
  
  <p>Therefore I tried a OpenCV's Canny Edge Detection and extracted the coordinates like this:</p>
  
  <pre><code>&gt;&gt;&gt; edge = cv2.Canny(region, 100, 200)
  &gt;&gt;&gt; ans = []
  &gt;&gt;&gt; for y in range(0, edge.shape[0]):
  &gt;&gt;&gt;     for x in range(0, edge.shape[1]):
              if edge[y, x] != 0:
                  ans = ans + [[x, y]]
  &gt;&gt;&gt; print ans
  </code></pre>
  
  <p>The problem is, that I'd like to extract the coordinates in an order like they are arranged in the boundary like <a href="http://i.stack.imgur.com/vI5Vv.png" rel="nofollow">this picture</a> might explain.</p>
  
  <p>As my polygons are complex, a convex hull did not work and because of the amount of the edge-points I get of cv2.edge() I need to use a fast algorithm.</p>