原理就是根据数据构建求解方程组,分析其系数矩阵的性质进行求解。
1 案例演示
Eigen::Vector2d ellipseFitting2D(const PCLPointCloud::Ptr points)
{
Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor> D1(points->points.size(), 3);
Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor> 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<double, 3, 3, Eigen::RowMajor> S1, S2, S3;
S1 = D1.transpose() * D1; // 3*3
S2 = D1.transpose() * D2; // 3*3
S3 = D2.transpose() * D2; // 3*3
E