title: Splitting Contour Into Subcontours Based on Straigtness
body: <p>I have a program which gets the contours of an image. I want to break these contours into sub-contours based on relative straightness. If the straightness of an extra pixel is less than a threshold value times the previous straightness, the contour should be split. When I put an image of a square drawn in paint, the program output should be 4 sub-contours. However, for some reason I get 3 sub-contours with 2 of them including 2-3 points and one including most of the original contour. Note, the 0.85 in my code is a threshold derived from a research paper. dPreious is the pixel distance of the edge(Not Including the Current Pixel). v is the euclidean distance between end-points.</p>
  
  <pre><code>def split(contour):
  new = [];
  toAdd = [];
  sCurrent = 0.0
  sPrevious = 0.0
  v = 0.0
  dPrevious = 1
  for points in range(0,len(contour)):
      currentX = float(contour[points][0])
      currentY = float(contour[points][1])
      if points != 0:
          v = math.sqrt(math.pow(float(toAdd[0][0])-currentX,2) + math.pow(float(toAdd[0][1])-currentY,2)) 
          dPrevious = len(toAdd)
      sCurrent = v/dPrevious
      if sCurrent &lt; 0.85*sPrevious:
          new.append(toAdd)
          toAdd = []
      toAdd.append(contour[points])
      sPrevious = sCurrent
  new.append(toAdd)
  return new
  </code></pre>