激光雷达(LiDAR)| Open3D:第五节 表面重建-体素化

本节基于Open3D中的体素化实现点云的表面重建:支持点point和网格mesh来实现体素化处理。

在这里插入图片描述

1. 体素化介绍

体素(voxel)即体积元素的简称,是数字数据在三维空间分割上的最小的单位。体素化就是通过创建三维体素网格来表示三维物体,是一种将无序点云变为有序点云的降采样的空间数据结构方法,便于实现点云的空间卷积。
在这里插入图片描述

2. 实现过程

# 加载包
import open3d as o3d
import numpy as np

2.1 基于点的体素化

采用create_from_point_cloud函数从点云创建体素网格,如果点云的至少一个点在体素内,则体素被占用。体素的颜色是体素内所有点的平均值。

# 读取点云
pcd = o3d.io.read_point_cloud("./tree/Tree_singel.pcd")
o3d.visualization.draw_geometries([pcd],width = 700, height = 900)

# fit to unit cube
print(pcd)
N = np.asarray(pcd.points).shape[0]
pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()), center=pcd.get_center())
# From numpy to Open3D
pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0,1,size=(N,3)))
o3d.visualization.draw_geometries([pcd])

在这里插入图片描述

# 体素化
print('voxelization')
voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd, voxel_size=0.01)
# 可视化
o3d.visualization.draw_geometries([voxel_grid])
# 同时显示点和体素
o3d.visualization.draw_geometries([pcd,voxel_grid],mesh_show_wireframe = True)

在这里插入图片描述

# 判断点是否占用体素
queries = np.asarray(pcd.points)
output = voxel_grid.check_if_included(o3d.utility.Vector3dVector(queries))
print(output[:20])

2.2 基于网格的体素化

采用create_from_triangle_mesh函数从点云创建体素网格,与三角形相交的所有体素设置为 1,所有其他体素设置为 0。

mesh = o3d.io.read_triangle_mesh("./bunny/bunny.ply")
# fit to unit cube
mesh.scale(1 / np.max(mesh.get_max_bound() - mesh.get_min_bound()),center=mesh.get_center())
o3d.visualization.draw_geometries([mesh])

在这里插入图片描述

mesh = o3d.io.read_triangle_mesh("./bunny/bunny.ply")
# fit to unit cube
mesh.scale(1 / np.max(mesh.get_max_bound() - mesh.get_min_bound()),center=mesh.get_center())
o3d.visualization.draw_geometries([mesh])

print('voxelization')
voxel_grid = o3d.geometry.VoxelGrid.create_from_triangle_mesh(mesh, voxel_size=0.006)
o3d.visualization.draw_geometries([voxel_grid])
o3d.visualization.draw_geometries([mesh,voxel_grid],mesh_show_wireframe = True)

在这里插入图片描述

2.3 补充

采用create_from_point_cloud_within_boundscreate_from_triangle_mesh_within_bounds函数对点和网格的体素化方法。

a = o3d.geometry.VoxelGrid.create_from_point_cloud_within_bounds(pcd, 0.02, pcd.get_min_bound(), pcd.get_max_bound())
o3d.visualization.draw_geometries([a])

b = o3d.geometry.VoxelGrid.create_from_triangle_mesh_within_bounds(mesh, 0.01, mesh.get_min_bound(), mesh.get_max_bound())
o3d.visualization.draw_geometries([b])

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值