日期:2014-05-17  浏览次数:20791 次

着急啊,各位! 请问谁有拟合圆的较好的方法和代码,另有200分相送,先谢了
RT

另外两个帖子

http://topic.csdn.net/u/20100704/22/4858039d-d110-4409-86cf-248082cb49d5.html

http://topic.csdn.net/u/20100704/22/47912825-d649-4fdf-9394-ceed8a55a9bd.html

------解决方案--------------------
没有,帮顶,希望楼主能早日解决问题
------解决方案--------------------
其实你最好解释下什么叫“拟合圆”
大家都不怎么知道 也不好解答了
------解决方案--------------------
如果你可以确定你的拟合函数,用c#写出来,那么画图不是问题,这个例子可以参考:
源代码下载,需要注册用户

//下面就是一个根据函数画图的演示
C# code
private GraphDataset DesignTimeDatasetTestSine ( int cPoints ) 
{ 
    float fxMin = 0; 
    float fxMax = (float) (Math.PI * 2); 
    float fxInc = (fxMax - fxMin) / (float)(cPoints + 1); 
    GraphDatastream gstrm = GraphDatastream.FromFunction( SineFunction, 
                                                     fxMin, fxMax, fxInc ); 
    GraphDatasetXY<float,float> gds
                = new GraphDatasetXY < float,float >("Angle", "Sine",gstrm); 
    return gds; 
} 
private void SineFunction ( float fx, out float fxOut, out float fyOut ) 
{ 
    fxOut = fx; 
    fyOut = (float) Math.Sin( (double) fx ); 
}

------解决方案--------------------
这里API和源码例子
一个英文的,一个翻译的:
http://apicode.gicp.net/class.do?api=selectByfatherIndex&father=255
http://apicodecn.gicp.net/class.do?api=selectByfatherIndex&father=255
------解决方案--------------------
下面是我的一个优化过的Hough变换检测直线的函数(C++写的,在VC6.0中调试的)。希望对你检测圆有帮助。拟合方法的最大弱点在于野点对于拟合结果的影响巨大
C/C++ code
void HoughTransform_Line(BYTE *pImg,int width,int height,int step_theta,int &theta, double &dthro)
//用(ρ,θ)空间实现直线霍夫变换,假设原点在图像左上角,x轴横向往右,y轴纵向往下。
//参数中的theta和dthro为检测得到的直线的(ρ,θ)值
{
    unsigned long *count;
    int theta1=-90,theta2=180;
    int numtheta=(theta2-theta1)/step_theta+1;
    int numthro=4*int(sqrt(width*width+height*height)+2);
    count=new unsigned long[numtheta*numthro];
    memset(count,0,sizeof(unsigned long)*numtheta*numthro);
    int size=width*height;

    BYTE *pCur,*pEnd=pImg+size;

    int *x=new int[size];
    int *y=new int[size];
    memset(x,0,sizeof(int)*size);
    memset(y,0,sizeof(int)*size);
    int n=0,i=0,j=0;
    for(pCur=pImg;pCur<pEnd;)
    {
        if((*(pCur++))==255)
        {
            x[n]=j;
            y[n]=i;
            n++;
        }
        j++;
        if(j==width)
        {
            i++;
            j=0;
        }
    }

    int thro;
    for(theta = theta1; theta<theta2; theta+=step_theta)
    {
        for(i=0; i<n; i++)
        {  
            thro = (x[i]*cosV[theta+90] + y[i]*sinV[theta+90]) >>9; // 相当于除以512
            if(thro>=0)    
                count[thro*numtheta+(theta+90)/step_theta]++;
        }
    } 
    
    int num=numtheta*numthro;
    unsigned long max=0,index=0;
    for(i=0;i<num;i++)
    {
        if(count[i]>max) 
        {
            max=count[i];
            index=i;
        }
    }
    theta=(index%numtheta)*step_theta-90;
    dthro=(double)index/numtheta/4;
    delete count;
    delete x;
    delete y;
    return;
}

------解决方案--------------------
拟合的原理很简单的,就是一个平方误差最小化的最优化问题,这个问题的解我想参考资料上应该可以查到了。楼主何不按照解的公式自己去实现一下呢?我想有公式的话,一个熟悉C#编程的人。可能10分钟不到就写好了。
------解决方案--------------------
没有,帮顶,希望楼主能早日解决问题
------解决方案--------------------
http://shwang112.blog.163.com/blog/static/447121012008102021445971/里有这个解的推导过程,具体的解析解。有了这些楼主不是可以实现了吗?
------解决方案--------------------