我正在研究从激光雷达接收到的3D点云。我将大量的点(最多10-1亿个)分割为多维数据集,研究它们的位置并使用Axes3D.voxels
方法将结果显示在单独的体素中。但是,Axes3D
在多次使用此方法设置适当的限制时,我会遇到一些问题。
我定义add_voxels
函数是为了从np.array
输入的多维数据集的位置立即显示体素:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import itertools
def add_voxels(true_ids, ax):
shape_of_filled = true_ids.max(axis=0) + 1 # shape of building
filled = np.zeros(shape_of_filled)
for n in true_ids:
filled[n] = 1
x, y, z = np.indices(np.array(shape_of_filled) + 1)
return ax.voxels(x,y,z, filled)```
Then use it to plot my two clouds of cubes:
fig = plt.gcf() # get a reference to the current figure instance
ax = fig.gca(projection='3d') # get a reference to the current axes instance
cubecloud1 = np.array(list(itertools.product(range(2,4), range(2,4), range(2,4))))
cubecloud2 = np.array(list(itertools.product(range(4,7), range(4,7), range(4,7))))
add_voxels(cubecloud2, ax)
add_voxels(cubecloud1, ax)
plt.show()
这会导致显示体素位置的限制很差:
我想将所有组件显示在这样的正确边界框中:
Or, at least, this (assuming bounding box includes invisible voxels too):
I could only make this work by setting the axis limits explicitly:
# [...]
faces2 = add_voxels(cubecloud2, ax)
faces1 = add_voxels(cubecloud1, ax)
points = list(faces1.keys()) + list(faces2.keys())
data = list(zip(*points))
xmin = min(data[0])
xmax = max(data[0])
ymin = min(data[1])
ymax = max(data[1])
zmin = min(data[2])
zmax = max(data[2])
ax.set_xlim3d(xmin, xmax)
ax.set_ylim3d(ymin, ymax)
ax.set_zlim3d(zmin, zmax)
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句