title: Get coordinates of non-geometric lines in a binary image
body: <p>I'm trying to recognize hand positions in <strong>OpenCV</strong> for Android. I'd like to reduce a detected hand shape to a <strong>set of simple lines (= point sequences)</strong>. I'm using a thinning algorithm to find the <strong>skeleton lines</strong> of detected hand shapes. Here's an exemplary result (image of my left hand):</p>
  
  <p><img src="https://i.stack.imgur.com/BQ7Pz.png" alt="enter image description here"></p>
  
  <p>In this image I'd like to get the coordinates of the skeleton lines, i.e. <strong>"vectorize"</strong> the image. I've tried <code>HoughLinesP</code> but this only produces huge sets of very short lines, which is not what I want.</p>
  
  <p><strong>My second approach uses</strong> <code>findContours</code><strong>:</strong></p>
  
  <pre><code>// Get contours
  Mat skeletonFrame; //image above
  ArrayList&lt;MatOfPoint&gt; contours = new ArrayList&lt;MatOfPoint&gt;();
  Imgproc.findContours(skeletonFrame, contours, new Mat(), Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_SIMPLE);
  
  // Find longest contour
  double maxLen = 0;
  MatOfPoint max = null;
  for (MatOfPoint c : contours) {
      double len = Imgproc.arcLength(Util.convert(c), true);  //Util.convert converts between MatOfPoint and MatOfPoint2f
      if (len &gt; maxLen) {
          maxLen = len;
          max = c;
      }
  }
  
  // Simplify detected contour
  MatOfPoint2f result = new MatOfPoint2f();
  Imgproc.approxPolyDP(Util.convert(max), result, 5.0, false);
  </code></pre>
  
  <p>This basically works; however, the contours returned by <code>findContours</code> are always closed, which means that <strong>all the skeleton lines are represented twice</strong>.</p>
  
  <p><strong>Exemplary result:</strong> (gray lines = detected contours, not skeleton lines of first image)</p>
  
  <p><img src="https://i.stack.imgur.com/Thxct.png" alt="enter image description here"></p>
  
  <p>So my question is: <strong>How can I avoid these closed contours and only get a collection of "single stroke" point sequences?</strong></p>
  
  <p>Did I miss something in the OpenCV docs? I'm not necessarily asking for code, a hint for an algorithm I could implement myself would also be great. Thanks!</p>