title: Is there a function similar to OpenCV findContours that detects curves and replaces points with a spline?
body: <p>I am trying to take the below image, trace the white shape, and export the resulting path to pdf. The problem I have is that findContours seeming only finds points along the edge of the shape. Is there a solution out there, similar to findContours, that detects curves in a shape and replaces its points with a spline wherever there is a curve? If I use scipy.interpolate it ignores straight lines and turns the entire contour into one big curved shape, which is no good either. I need something that does both things.</p>
  
  <p><a href="https://i.stack.imgur.com/zU7Yv.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/zU7Yv.jpg" alt=""></a></p>
  
  <pre><code>import numpy as np
  import cv2
  from scipy.interpolate import splprep, splev
  from pyx import *
  import matplotlib.pyplot as plt
  
  #read in image file                                                             
  original = cv2.imread('test.jpg')
  
  #blur the image to smooth edges                                                 
  im = cv2.medianBlur(original,5)
  
  #threshold the image                                                            
  imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
  ret,thresh = cv2.threshold(imgray,170,255,cv2.THRESH_BINARY)                                                             
  
  #findContours                                                                   
  im2, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_\
  APPROX_SIMPLE)
  
  #drawContours
  cv2.drawContours(original, [approx], -1, (0,255,0), 3)                          
  cv2.imshow("Imageee", original)                                                 
  cv2.waitKey(0)
  </code></pre>