title: Extract single line contours from Canny edges
body: <p>I'd like to extract the contours of an image, expressed as a sequence of point coordinates.</p>
  
  <p>With <code>Canny</code> I'm able to produce a binary image that contains only the edges of the image. Then, I'm trying to use <code>findContours</code> to extract the contours. The results are not OK, though.</p>
  
  <p>For each edge I often got 2 lines, like if it was considered as a very thin area.
  I would like to simplify my contours so I can draw them as single lines. Or maybe extract them with a different function that directly produce the correct result would be even better.</p>
  
  <p>I had a look on the documentation of OpenCV but I was't able to find anything useful, but I guess that I'm not the first one with a similar problem. Is there any function or method I could use?</p>
  
  <p>Here is the Python code I've written so far:</p>
  
  <pre><code>def main():
      img = cv2.imread("lena-mono.png", 0)
  
      if img is None:
          raise Exception("Error while loading the image")
  
      canny_img = cv2.Canny(img, 80, 150)
  
      contours, hierarchy = cv2.findContours(canny_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
      contours_img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
  
      scale = 10
      contours_img = cv2.resize(contours_img, (0, 0), fx=scale, fy=scale)
  
      for cnt in contours:
          color = np.random.randint(0, 255, (3)).tolist()
          cv2.drawContours(contours_img,[cnt*scale], 0, color, 1)
  
      cv2.imwrite("canny.png", canny_img)
      cv2.imwrite("contours.png", contours_img)
  </code></pre>
  
  <p>The scale factor is used to highlight the double lines of the contours.
  Here are the links to the images:</p>
  
  <ul>
  <li><a href="https://docs.google.com/file/d/0BxpQXkAT_TOhVHJ1N24wS2szdms/edit?usp=sharing" rel="noreferrer">Lena</a> greyscale</li>
  <li><a href="https://docs.google.com/file/d/0BxpQXkAT_TOhZEJTM1hzcFhrbUE/edit?usp=sharing" rel="noreferrer">Edges</a> extracted with <code>Canny</code></li>
  <li><a href="https://docs.google.com/file/d/0BxpQXkAT_TOhSzVPZGw1LUhWTU0/edit?usp=sharing" rel="noreferrer">Contours</a>: 10x zoom where you can see the <em>wrong</em> results produced by <code>findContours</code></li>
  </ul>
  
  <p>Any suggestion will be greatly appreciated.</p>