Disclaimer: I am in no way an expert in statistics, so much of the details is beyond me. This is just an explanation of my attempt to solve the problem I had.
Recently, I was working with some cool stuff in image processing. I had to extract some shapes after binarizing some images. The final task was to smoothen the contours extracted from the shapes to give it a better feel.
After researching around a bit, the task was clear. All I had to do was resample the points in the contours at regular intervals and draw a spline through the control points. But opencv had no native function to do this. So I had to resort to numpy. Now, another problem in numpy was the data representation. Though opencv uses numpy internally, you have to jump through a couple of hoops to get everything running along smoothly.
Without wasting further time, here’s the code -
Get the contours from the binary image-
Now comes the numpy code to smoothen each contour-
P.S.: Credit has to be given to this SO answer which served as the starting point.
As you can see, data conversion is required to pass to splprep
. And then again, when you are appending to the list to overlay on the image.
Hope you found it useful. If you have a better way to achieve the same result, please do not hesitate to let me know in the comments !