# What method to use to get a fitted curve

Hi, I am looking at a video of a, say Ice Hockey game. My goal is to detect the external boundary of the perimter board. But, of course there are players blocking the view. I was able to set some threshold and am able to generate contours of the visibile perimter board. I am able to detect the contour reasonably well. But, the contours are not smooth. When I draw the contours, the edges are jagged. What method can I use to approximate and draw a smooth fitted curv e? The curve need not pass through all the points , per se.

I have tried the approxpolydp function.but that is not providing a good output as per my requirement.

Have you tried convexHull on the contour of the "perimter" board? Or maybe you can use convexityDefects, they are both on this doc Or maybe fitEllipse will help, for eliminating the defects? maybe you can put some results and a little explanation of what you have and what you want...

Dear thdrksdfthmm, I have uploaded a sample contour to this link. Sample1Sample2 What I am looking for is a smooth line not what I see. Probably a mix of interpolation and approximation? Do you think the convexHull or the convexityDefects would get me my results?

Thanks

Actually I was supposing that you have the contour of the ice, like between the line you have and the bottom borders of the image, so convex hull will eliminate the "wholes" (approximate with a straight line between the two true points on your line). I have some ideas, but they are not clear in my head :D like detection of defects based on the angle between the points of the line, or corners... Or reconstruction

I can extract the bottom border as well. But, thats not straight either - with the players and other obstacles in between. So, My goal was to run through this step twice - once for the top and another for the bottom. Do you think I should follow a different approach?

I am not sure if you have not already tried to extract the contour of the ice, then apply the convexHull on it, so it will eliminate the holes (like in

Sample2), and then try to find something to remove the spikes (like inSample1); and for the last part I thought of something like a for loop over the points of the contour and if the angle between 3 consecutive points is not around 180°, then remove point in the meddle, and check again the angle between the first point, (the second is removed) the third and the next one (the point of the angle is in meddle). Be careful at the image borders. Maybe you can apply this on your lines? More I think you need something like background extraction on moving camera, or multi cams (google search, I think that there are approaches for it).Hi, Thanks for your inputs, as always. I am applying a color filter to get the PB. Then removing noise by deleting areas with small area. I have not used convexHull though. I will try and see if I can get something different with that. Then I have already used the technique with the angle between points. Though a slightly different approach. I check if the angle between points are not above and below a threshold and that the slope of the line is continuous. I have not used the convexHull to see the difference it gets me. It is tough to get a background extractions as the stuff on the PB changes with moving camera. I THINK ( i could be way out though) all I need is a neat method to fill in the spikes and make it a smooth curve. Thats the implementation that I am looking for.

Thanks

So you are saying that the approach based on the slope of the curve is preserving the defects you are showing in the images? I suppose that is because of 2 of the 3 points that are very close, maybe you can also add a constrain about the length of the segment. Do you understand what I mean?

Some of the points on the curve are very close and a few of them are far apart. So, On certain frames, this would work. But, in many frames, the curve will not be smoother since I will have to reject a lot of points on between right. What seems to be a simple thing for the human brain to take a pencil and smooth out the curves , seems tough to implement. :), atleast for me

So just pick the 3 consecutive points and if the first 2 are very close, then move to the first, the 3rd and the 4th, so shift the last two; do this until a minimal distance between the first 2 points, then check the dist between the last 2 points, and shift the last one until enough dist. This I suppose that will eliminate the defects.