# cubic spline interpolation on contour points

I have traced the boundary of an object using openCV as shown in the figure :

I have vectorX and vectorY holding the x-axis and y-axis coordinates of above curve. Th curve looks fine but when we zoom it in we find that the curve is not smooth i.e. jagged:

I require smooth curve before further processing. In MATLAB, we can use CSAPS (Cubic smoothing spline) to smooth such curves and it works pretty well. I am looking to do the same thing either using openCV or some free C++ library. I am looking to get an output like the following (where curve is smoothed by CSAPS function):

Any help will be really appreciated in this regard.

My code:

```
ret,thresh = cv2.threshold(imgray,50,255, cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
xSample = np.flipud(contours[0][:,0,0])
ySample = np.flipud(contours[0][:,0,1])
arraySample = np.vstack([xSample, ySample])
arraySample = arraySample.T
plt.figure(2)
plt.plot(arraySample[:,0], arraySample[:,1], 'ro-')
plt.show()
```

Sorry,could you post your code?It's helpful for everyone.

code is added

hi, maybe you can try draws contours outlines:drawContours or filled contours drawContours or Approximates a polygonal curve(s) with the specified precision :approxPolyDP

I also need to preserve the sequence of points for complex objects. After drawing contour, I cannot keep track of it .. Moreover, it's still not smooth (I tired that)

I think you use python,in numpy, there is a fununction:numpy.polyfit.I think it's helpful.

yes, I can apply interpolation in python. Though looking for alternative in C++