Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cubic spline interpolation on contour points

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

image description

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:

image description

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):

image description

Any help will be really appreciated in this regard.

cubic spline interpolation on contour points

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

image description

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:

image description

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):

image description

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()