把一个点云numpy,按照z轴相同值,拆分成多个numpy
时间: 2023-11-10 22:04:21 浏览: 42
可以先对点云按照z轴的值进行排序,然后遍历点云,将相邻的z值相同的点分为一组,存储到一个新的numpy数组中。
以下是示例代码:
```python
import numpy as np
def split_point_cloud(point_cloud):
# 按照z轴的值进行排序
sorted_indices = np.argsort(point_cloud[:, 2])
sorted_point_cloud = point_cloud[sorted_indices]
# 遍历点云,将相邻的z值相同的点分为一组
split_point_clouds = []
current_z = sorted_point_cloud[0, 2]
current_group = [sorted_point_cloud[0]]
for i in range(1, sorted_point_cloud.shape[0]):
if sorted_point_cloud[i, 2] == current_z:
current_group.append(sorted_point_cloud[i])
else:
# 当前z值与前一个不同,将当前组加入到结果中
split_point_clouds.append(np.array(current_group))
# 开始新的一组
current_z = sorted_point_cloud[i, 2]
current_group = [sorted_point_cloud[i]]
# 将最后一组加入到结果中
split_point_clouds.append(np.array(current_group))
return split_point_clouds
```
使用示例:
```python
point_cloud = np.array([[1, 2, 3], [4, 5, 3], [7, 8, 3], [2, 3, 6], [5, 6, 6], [8, 9, 6]])
split_point_clouds = split_point_cloud(point_cloud)
print(split_point_clouds)
```
输出结果:
```
[array([[1, 2, 3],
[4, 5, 3],
[7, 8, 3]]),
array([[2, 3, 6],
[5, 6, 6],
[8, 9, 6]])]
```
可以看到,点云被成功拆分成了两个numpy数组,每个数组中的点的z轴值都相同。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)