一、准备
3D模型文件
安装包:pip install open3d
二、代码与运行结果
2)点云查看斯坦福兔子
import open3d as o3d
import numpy as np
print('Open3D read Point Cloud')
pcd=o3d.io.read_point_cloud(r'D:\py2021\C8-open 3D\bunny10k.ply')
print(pcd)
o3d.visualization.draw_geometries([pcd],width=800,height=600)
o3d.io.write_point_cloud(r"d:\py2021\C8-open 3D\bunny\data\newrabbit.pcd",pcd)
成功运行
2)法向量兔子
##--------法向量--------------
import open3d as o3d
import numpy as np
print("Open3D read Point Cloud")
pcd = o3d.io.read_point_cloud(r"d:\py2021\C8-open 3D\bunny10k.ply")
print(pcd)
dumppcd = pcd.voxel_down_sample(voxel_size=0.01) #下采样(降采样)
dumppcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.01,max_nn=30))
print(dumppcd.normals[0])
print(np.asarray(dumppcd.normals)[:10,:])
o3d.visualization.draw_geometries([dumppcd],point_show_normal=True,
window_name="法线估计", width=1200,height=1000, mesh_show_back_face=False)
3)近邻搜索兔子
import open3d as o3d
import numpy as np
###——————近邻搜索点云图————————————
print("Open3D read Point Cloud")
pcd = o3d.io.read_point_cloud(r"d:\py2021\C8-open 3D\bunny10k.ply")
pcd.paint_uniform_color([0.5, 0.5, 0.5])
pcd_tree = o3d.geometry.KDTreeFlann(pcd)
pcd.colors[100] = [1, 0, 0]
#[k, idx, _] = pcd_tree.search_knn_vector_3d(pcd.points[100],100)
#np.asarray(pcd.colors)[idx[1:], :] = [0, 1, 0]
#o3d.visualization.draw_geometries([pcd],width=1200,height=1000)
[k,idx,_] = pcd_tree.search_radius_vector_3d(pcd.points[3000],0.1) #索引半径小于0.02
np.asarray(pcd.colors)[idx[1:], :] = [0, 1, 0]
o3d.visualization.draw_geometries([pcd],width=1200,height=1000)
4)三角片面兔子:
代码
import open3d as o3d
#import open3d_tutorial as o3dtut ?这句的作用,不注释掉会报错
import numpy as np
print("Open3D read Point Cloud")
pcd = o3d.io.read_triangle_mesh(r"d:\py2021\C8-open 3D\bunny10k.ply")
print(pcd)
pcd.compute_vertex_normals()
pcdmesh = pcd.sample_points_poisson_disk(3000)
o3d.visualization.draw_geometries([pcdmesh],point_show_normal=True)
radii=[0.005, 0.01, 0.02, 0.04]
ballmesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(pcdmesh,o3d.utility.DoubleVector(radii))
print(ballmesh)
o3d.visualization.draw_geometries([ballmesh])
o3d.visualization.draw_geometries([pcd, ballmesh])
三、错误
文件路径写错,导致无法识别
版权声明:本文为chenshiman0324原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。