点云的区域增长聚类算法 (附open3d python代码)

本文介绍了作者自行编写的Python版点云区域增长聚类算法,旨在填补Python实现这一领域的空白。通过算法应用,实现了有效的点云处理效果。
摘要由CSDN通过智能技术生成

 因为没有看到有python版本的点云区域增长代码,所以自己写了一个,效果如下:

 


# -*-coding:utf-8 -*-
import open3d as o3d
import matplotlib.pyplot as plt
import os
import numpy as np



def angle2p(N1, N2):
    # Input two normals, return the angle
    dt = N1[0] * N2[0] + N1[1] * N2[1] + N1[2] * N2[2]
    dt = np.arccos(np.clip(dt, -1, 1))
    r_Angle = np.degrees(dt)
    return r_Angle


class RegionGrowing:
    def __init__(self):
        """
           Init parameters
        """
        self.pcd = None  # input point clouds
        self.NPt =
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
下面是使用Python实现基于点云数据的区域生长聚类算法的示例代码: ```python import open3d as o3d import numpy as np def region_growing_clustering(pcd, seed_idx, radius): """ 基于点云数据的区域生长聚类算法 :param pcd: 点云数据 :param seed_idx: 种子点的索引 :param radius: 区域生长半径 :return: 聚类结果 """ # 获取点云中所有点的坐标 points = np.asarray(pcd.points) # 创建一个与点云大小相同的数组,用于存储标记结果 marked = np.zeros(len(points)) # 将种子点添加到生长队列中 seed_list = [] seed_list.append(seed_idx) # 循环遍历生长队列,直到队列为空 while(len(seed_list) > 0): # 从队列中获取当前生长点 current_point_idx = seed_list.pop(0) # 获取当前生长点的坐标 current_point = points[current_point_idx] # 遍历当前生长点周围的点 for i, point in enumerate(points): # 如果当前点已经被标记过,则跳过 if(marked[i] == 1): continue # 计算当前点与生长点的距离 distance = np.linalg.norm(point - current_point) # 如果当前点在生长半径内,则将其添加到生长队列中,并标记为已处理 if(distance < radius): seed_list.append(i) marked[i] = 1 # 将标记结果转换为聚类结果 clusters = [] current_cluster = [] for i in range(len(marked)): if(marked[i] == 1): current_cluster.append(i) else: if(len(current_cluster) > 0): clusters.append(current_cluster) current_cluster = [] if(len(current_cluster) > 0): clusters.append(current_cluster) # 返回聚类结果 return clusters ``` 该函数需要三个参数:点云数据、种子点的索引以及区域生长半径。函数将以种子点为中心开始生长,并标记所有与该点之间距离小于生长半径的点。最终,函数将返回一个列表,其中每个元素表示一个聚类簇,每个聚类簇由一组点的索引组成。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

点云-激光雷达-Slam-三维牙齿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值