基于Eigen的椭圆拟合

原理就是根据数据构建求解方程组,分析其系数矩阵的性质进行求解。

1 案例演示





Eigen::Vector2d ellipseFitting2D(const PCLPointCloud::Ptr points)
{
  Eigen::Matrix D1(points->points.size(), 3);
  Eigen::Matrix D2(points->points.size(), 3);

  for (size_t i = 0; i < points->points.size(); ++i)
  {
    double x = points->points[i].x;
    double y = points->points[i].y;

    D1.row(i) << x * x, x * y, y * y;
    D2.row(i) << x, y, 1;
  }

  Eigen::Matrix S1, S2, S3;
  S1 = D1.transpose() * D1;  // 3*3
  S2 = D1.transpose() * D2;  // 3*3
  S3 = D2.transpose() * D2;  // 3*3

  Eigen::Matrix T, M1, M2;
  T = -S3.inverse() * S2.transpose();
  M1 = S1 + S2 * T;

  M2.row(0) = M1.row(2) / 2.0;
  M2.row(1) = -M1.row(1);
  M

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