PCD点云文件直接提取的是点云的坐标,不是最外面的box的坐标,因此可以通过:
max_b = octree.get_max_bound()
min_b = octree.get_min_bound()
分别得到最大最小的xyz坐标,之后进行计算
点的序号和位置对应如下:
所有的代码如下,注意将pcd文件和代码置于同一文件夹中:
import numpy as np
import open3d as o3d
# --------------------------- 加载点云 ---------------------------
print("->正在加载点云... ")
pcd = o3d.io.read_point_cloud("clean.pcd")
# ------------------------- 构建Octree --------------------------
octree = o3d.geometry.Octree(max_depth=4)
octree.convert_from_point_cloud(pcd, size_expand=0.0)
s = octree.size
max_b = octree.get_max_bound()
min_b = octree.get_min_bound()
x_max, y_max, z_max = max_b
x_min, y_min, z_min = min_b
pb_1 = [x_max, y_max, z_min]
pb_2 = [x_max, y_max - (s / 2), z_min]
pb_3 = [x_max, y_min, z_min]
pb_4 = [x_max - (s / 2), y_min, z_min]
pb_5 = [x_min, y_min, z_min]
pb_6 = [x_min, y_min + (s / 2), z_min]
pb_7 = [x_min, y_max, z_min]
pb_8 = [x_min + (s / 2), y_max, z_min]
pb_9 = [x_max - (s / 2), y_max - (s / 2), z_min]
pb = [pb_1, pb_2, pb_3, pb_4, pb_5, pb_6, pb_7, pb_8, pb_9]
pu_1 = [x_max, y_max, z_max]
pu_2 = [x_max, y_max - (s / 2), z_max]
pu_3 = [x_max, y_min, z_max]
pu_4 = [x_max - (s / 2), y_min, z_max]
pu_5 = [x_min, y_min, z_max]
pu_6 = [x_min, y_min + (s / 2), z_max]
pu_7 = [x_min, y_max, z_max]
pu_8 = [x_min + (s / 2), y_max, z_max]
pu_9 = [x_max - (s / 2), y_max - (s / 2), z_max]
pu = [pu_1, pu_2, pu_3, pu_4, pu_5, pu_6, pu_7, pu_8, pu_9]
pm_1 = [x_max, y_max, z_max - (s / 2)]
pm_2 = [x_max, y_max - (s / 2), z_max - (s / 2)]
pm_3 = [x_max, y_min, z_max - (s / 2)]
pm_4 = [x_max - (s / 2), y_min, z_max - (s / 2)]
pm_5 = [x_min, y_min, z_max - (s / 2)]
pm_6 = [x_min, y_min + (s / 2), z_max - (s / 2)]
pm_7 = [x_min, y_max, z_max - (s / 2)]
pm_8 = [x_min + (s / 2), y_max, z_max - (s / 2)]
pm_9 = [x_max - (s / 2), y_max - (s / 2), z_max - (s / 2)]
pm = [pm_1, pm_2, pm_3, pm_4, pm_5, pm_6, pm_7, pm_8, pm_9]
print("最下面的9个点的坐标分别为: ")
for i in range(9):
print("{}: {}".format(i + 1, pb[i]))
print("中间的的9个点的坐标分别为: ")
for i in range(9):
print("{}: {}".format(i + 1, pm[i]))
print("最上面的9个点的坐标分别为: ")
for i in range(9):
print("{}: {}".format(i + 1, pu[i]))