且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使平面适合 3D 点云?

更新时间:2021-09-17 23:40:39

根据你的问题,我假设你熟悉 Ransac 算法,所以我就不多说了.

From you question I assume that you are familiar with the Ransac algorithm, so I will spare you of lengthy talks.

第一步,您对三个随机点进行采样.您可以使用 Random 类,但选择不是真正随机的通常会更好结果.对于这些点,您可以使用 Hyperplane::Through 简单地拟合平面.

In a first step, you sample three random points. You can use the Random class for that but picking them not truly random usually gives better results. To those points, you can simply fit a plane using Hyperplane::Through.

在第二步中,您用大Hyperplane::absDistance 并对剩余的进行最小二乘拟合.它可能看起来像这样:

In the second step, you repetitively cross out some points with large Hyperplane::absDistance and perform a least-squares fit on the remaining ones. It may look like this:

Vector3f mu = mean(points);
Matrix3f covar = covariance(points, mu);
Vector3 normal = smallest_eigenvector(covar);
JacobiSVD<Matrix3f> svd(covariance, ComputeFullU);
Vector3f normal = svd.matrixU().col(2);
Hyperplane<float, 3> result(normal, mu);

不幸的是,函数 meancovariance 不是内置的,但它们编写起来相当简单.

Unfortunately, the functions mean and covariance are not built-in, but they are rather straightforward to code.