0
点赞
收藏
分享

微信扫一扫

open3d学习笔记三【体素化】

卿卿如梦 2022-03-11 阅读 58
学习python

open3d学习笔记之体素化

以mesh方式读取ply文件

import open3d as o3d

mesh = o3d.io.read_triangle_mesh("mode/Fantasy Dragon.ply")
mesh.compute_vertex_normals()

龙

转化为点云的方式

一、转化为numpy数组再重新绘制成点云

import open3d as o3d
import numpy as np

mesh = o3d.io.read_triangle_mesh("mode/Fantasy Dragon.ply")
mesh.compute_vertex_normals()
v_mesh = np.asarray(mesh.vertices)

pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(v_mesh)
o3d.visualization.draw_geometries([pcd], width=1280, height=720)

在这里插入图片描述
对于ply格式的文件还好,但若是stl这种三角形网格,转化的结果会有点不理想。
在这里插入图片描述

二、采样

open3d提供了一种采样方式,可设置采样点,简化模型。

import open3d as o3d

mesh = o3d.io.read_triangle_mesh("mode/ganyu.STL")
mesh.compute_vertex_normals()
pcd = o3d.geometry.TriangleMesh.sample_points_uniformly(mesh, number_of_points=10000) # 采样点云
o3d.visualization.draw_geometries([pcd], width=1280, height=720)

在这里插入图片描述

体素化

体素化,能简化模型,得到均匀网格。

将三角网格转化为体素网格

import open3d as o3d
import numpy as np

print("Load a ply point cloud, print it, and render it")
mesh = o3d.io.read_triangle_mesh("mode/ganyu.STL")
mesh.compute_vertex_normals()

mesh.scale(1 / np.max(mesh.get_max_bound() - mesh.get_min_bound()), center=mesh.get_center())

voxel_grid = o3d.geometry.VoxelGrid.create_from_triangle_mesh(mesh, voxel_size=0.05)

o3d.visualization.draw_geometries([voxel_grid], width=1280, height=720)

在这里插入图片描述

点云生成体素网格

import open3d as o3d
import numpy as np

print("Load a ply point cloud, print it, and render it")
pcd = o3d.io.read_point_cloud("mode/Fantasy Dragon.ply")

pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()), center=pcd.get_center())
pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0,1,size=(2000,3)))

print('voxelization')
voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd, voxel_size=0.05)

o3d.visualization.draw_geometries([voxel_grid], width=1280, height=720)

在这里插入图片描述

法向

voxel_down_pcd = pcd.voxel_down_sample(voxel_size=0.05)
voxel_down_pcd.estimate_normals(
    search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.1, max_nn=30))
o3d.visualization.draw_geometries([voxel_down_pcd], point_show_normal=True, width=1280, height=720)

在这里插入图片描述

举报

相关推荐

0 条评论