Need to redraw curve with the minimal control points of Nurbs curve from many imported points

Hi, I have a set of (x y), points that extract tracing from a photo.
Have more than 200 points that define a edge profile, it have some hand errors.

So I want to regenerate the geometry, without imperfections and with smoth continuity.
The regenerated geometry will be used in a CNC machine.

The idea is get the minimal set of point to generate the same curve with a minimal seted gap.

The point are readed from txt in python and loaded in a NurbsCurve.

points = Loadfile(profile.txt);
NCpCrv1 = rhino.Geometry.NurbsCurve.CreateControlPointCurve(points,3);
scriptcontext.doc.Objects.AddCurve(NCpCrv1);

The picture show:
Curve in red the readed point, with many control points.
Curve in black is that I wanted, but is hand drawed.

So there is any script, math o algorithm to regenerate the curve ?
I need some python o C# code to calculate the minimal set of point.
Greetings

Generally Rhino’s FitCrv command does this (with varying degrees of success), you can also access it directly in RhinoCommon via python or C# : http://developer.rhino3d.com/api/RhinoCommonWin/html/M_Rhino_Geometry_Curve_Fit.htm

–Mitch

Thansk,
The Rhinno api is a endless world

    def FitCurve():
    
    guid1 = rs.GetObject("Select curve to fit:", 4, True, False)
    if not guid1: return
    
    curve1 = rs.coercecurve(guid1)    
    fit = curve1.Fit(3,5,0)            

    scriptcontext.doc.Objects.AddCurve(fit)