计算点云每个点的粗糙度(附open3d python代码)

计算一个个点的周围N个点拟合的平面,然后计算该点到这个平面的距离,作为该点的粗糙度;
每个点的粗糙度平均值就是这个点云的整体粗糙度


# coding:utf-8
import open3d as o3d
import numpy as np
from numpy.linalg import norm
from numpy.linalg import svd


def planeFit(points):
    """
    p, n = planeFit(points)

    Given an array, points, of shape (d,...)
    representing points in d-dimensional space,
    fit an d-dimensional plane to the points.
    Return a point, p, on the plane (the point-cloud centroid),
    and the normal, n.
    """
    points = np.transpose(points)
    points = np.reshape(points, (np.shape(points)[0], -1)) # Collapse trialing dimensions
    assert points.shape[0] <= points.shape[1], "There are only {} points in {} dimensions.".format(points.shape[1], points.shape[0])
    ctr = points.mean(axis=1)
    x = points - ctr[:, np.newaxis]
    M = np.dot(x, x.T) # Could also use np.cov(x) here.

你可能感兴趣的:(点云处理代码合集,python,开发语言,numpy,算法)