[英]How to extract the bottom layer voxels using open3d?
我想提取底層體素。 例如,從犰狳中提取部分。 有誰知道這是怎么做到的嗎?
這就是我找到最低體素的方法。
#Get voxels center coordinate
def get_voxel_center_coordinate(voxel_grid):
voxels = voxel_grid.get_voxels()
voxel_center = []
for voxel in voxels:
voxel_center.append(voxel_grid.get_voxel_center_coordinate(voxel.grid_index))
return voxel_center
#Find lowest voxels index
def find_lowest_voxel_index(voxel_grid):
voxels = voxel_grid.get_voxels()
voxel_center = get_voxel_center_coordinate(voxel_grid)
for i in range(0, len(voxel_center)):
if i == 0:
min_z = voxel_center[i, 2]
else:
if min_z > voxel_center[i, 2]:
min_z = voxel_center[i, 2]
ind = 0
lowest_voxel_index = []
for center in voxel_center:
if center[2] == min_z:
print(center[2])
lowest_voxel_index.append(voxels[ind].grid_index)
ind += 1
return lowest_voxel_index
您的解決方案幾乎是正確的。 我會指出一些你應該改變的事情,然后是一種驗證解決方案的方法。
給定解決方案中應該改變的事情:
voxel_center[i, 2]
訪問 z 軸,因為voxel_center
是一個列表,而不是一個 numpy 數組。 您應該改為以voxel_center[i][2]
的形式訪問它們。ind
,而不僅僅是在條件為真時。 或者,您可以使用enumerate
干凈地克服了這個問題。因此,正確的實現如下:
#Get voxels center coordinate
def get_voxel_center_coordinate(voxel_grid):
voxels = voxel_grid.get_voxels()
voxel_center = []
for voxel in voxels:
voxel_center.append(voxel_grid.get_voxel_center_coordinate(voxel.grid_index))
return voxel_center
#Find lowest voxels index
def find_lowest_voxel_index(voxel_grid):
voxels = voxel_grid.get_voxels()
voxel_center = get_voxel_center_coordinate(voxel_grid)
for i in range(0, len(voxel_center)):
if i == 0:
min_z = voxel_center[i][2]
else:
if min_z > voxel_center[i][2]:
min_z = voxel_center[i][2]
ind = 0
lowest_voxel_index = []
for center in voxel_center:
if center[2] == min_z:
print(center[2])
lowest_voxel_index.append(voxels[ind].grid_index)
ind += 1
return lowest_voxel_index
要驗證解決方案,您可能需要可視化結果。 然而, VoxelGrid
沒有任何方法允許用戶更改特定體素的顏色。 因此,您可以考慮創建額外的網格來可視化過濾后的體素。 由於VoxelGrid
提供get_voxel_bounding_points
,您可以利用這些點來創建AxisAlignedBoundingBox
。
lowest_index = find_lowest_voxel_index(voxel_grid) # this uses your solution after modifications
bounding_box = []
for i in lowest_index:
bb = o3d.geometry.AxisAlignedBoundingBox.create_from_points(voxel_grid.get_voxel_bounding_points(i))
bb.color = np.array([1,0,1]) # feel free to choose any other color
bounding_box.append(bb)
axes = o3d.geometry.TriangleMesh.create_coordinate_frame(origin=np.array([100,100,100]), size=100) # in order to be sure of the direction
o3d.visualization.draw_geometries([voxel_grid, *bounding_box, axes])
這就是在犰狳網格上運行此代碼的樣子。 請注意,我添加了坐標系以確保方向。 藍色箭頭指向 +z。 z 值最低的體素具有紫色邊緣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.