7.常见的点云数据处理方法

在更新中。。。

一、对点云数据的聚类处理

        这里参考了微博用Python打造无人驾驶车-激光雷达数据(1) - 知乎 (zhihu.com),这篇博文的聚类算法的分类有一些缺陷,所以本人对其代码稍微的修改,具体代码如下:

import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib


def cluster(points, radius=0.2):
    """
    points: pointcloud
    radius: max cluster range
    """
    items = []
    while len(points)>1:
        item = np.array([points[0]])
        base = points[0]
        points = np.delete(points, 0, 0)
        distance = (points[:,0]-base[0])**2+(points[:,1]-base[1])**2
        infected_points = np.where(distance <= radius**2)
        item = np.append(item, points[infected_points], axis=0)
        border_points = points[infected_points]
        points = np.delete(points, infected_points, 0)
        while len(border_points) > 0:
            border_base = border_points[0]
            border_points = np.delete(border_points, 0, 0)
            border_distance = (points[:,0]-border_base[0])**2+(points[:,1]-border_base[1])**2
            border_infected_points = np.where(border_distance <= radius**2)
            item = np.append(item, points[border_infected_points], axis=0)
            #for循环替代了原博文下面注释的一行
            for k in border_infected_points:
                if points[k] not in border_points:
                    border_points=np.append(border_points,points[k], axis=0)
            #border_points = points[border_infected_points]
            points = np.delete(points, border_infected_points, 0)
        items.append(item)
    return items

if __name__ == '__main__':

    points=[]#这里的points就是我们前一章获得的点云,返回的item
    fig=cluster(points, radius=0.2)
    fig = plt.figure()
    ax = Axes3D(fig)
    fig = plt.figure()
    ax = Axes3D(fig)
    ax.scatter(item[:,0], item[:,1], item[:,2], s=1)
    fig.show()

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值