LS最小二乘圆拟合

1.  方式1(直接基于最小二乘的数学解析解)

bool circle_LS(const vector& points, double& center_x, double& center_y, double& radius)
{
  center_x = 0.0;
  center_y = 0.0;
  radius = 0.0;
  if (points.size() < 3)
  {
    return false;
  }

  double sum_x = 0.0, sum_y = 0.0;
  double sum_x2 = 0.0, sum_y2 = 0.0;
  double sum_x3 = 0.0, sum_y3 = 0.0;
  double sum_xy = 0.0, sum_x1y2 = 0.0, sum_x2y1 = 0.0;

  int N = points.size();
  for (int i = 0; i < N; i++)
  {
    double x = points[i].x;
    double y = points[i].y;
    double x2 = x * x;
    double y2 = y * y;
    sum_x += x;
    sum_y += y;
    sum_x2 += x2;
    sum_y2 += y2;
    sum_x3 += x2 * x;
    sum_y3 += y2 * y;
    sum_xy += x * y;
    sum_x1y2 += x * y2;
    sum_x2y1 += x2 * y;
  }

  double C, D, E, G, H;
  double a, b, c

你可能感兴趣的:(3D点云,OpenCV,算法)