目录
三维空间建模
三维空间什么都没有,摄像机视角即为人眼视角,默认材质近似纸张
安装包-open3d
!pip install open3d
错误解决
报错
ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
错误解决
!pip install --ignore-installed PyYAML
再次安装open3d,成功安装
多种点云方法
使用素材:斯坦福兔子
多角度点云拼接在一起生成整个点云
import open3d as o3d
import numpy as np
print("Open3D read Point Cloud")
pcd=o3d.io.read_point_cloud(r"/Users/mac/Desktop/courses/ad/python/20211119/bunny10k.ply")
print(pcd)
o3d.visualization.draw_geometries([pcd],width=800,height=600)
共有6164个点
近邻搜索
以某一点为中心进行搜索
在选择中心点时应注意,不能超过6164
import open3d as o3d
import numpy as np
print("Open3D read Point Cloud")
pcd = o3d.io.read_point_cloud(r"/Users/mac/Desktop/courses/ad/python/20211119/bunny10k.ply")
pcd.paint_uniform_color([0.5, 0.5, 0.5])#将所有点设置为灰色
pcd_tree = o3d.geometry.KDTreeFlann(pcd)
pcd.colors[100] = [1, 0, 0]#设置第100个点为红色
[k, idx, _] = pcd_tree.search_knn_vector_3d(pcd.points[100],100)#搜索第100个点周边的100个点
np.asarray(pcd.colors)[idx[1:], :] = [0, 1, 0]#将周边的点设置为绿色
o3d.visualization.draw_geometries([pcd],width=1200,height=1000)
混合搜索
要同时告知半径
import open3d as o3d
import numpy as np
print("Open3D read Point Cloud")
pcd=o3d.io.read_point_cloud("/Users/mac/Desktop/courses/ad/python/20211119/bunny10k.ply")
pcd.paint_uniform_color([0.5,0.5,0.5])
pcd_tree=o3d.geometry.KDTreeFlann(pcd)
pcd.colors[2000]=[1, 0, 0]
[k2, idx2, _]=pcd_tree.search_hybrid_vector_3d(pcd.points[2000],0.05,200)
np.asarray(pcd.colors)[idx2[1:], :] = [0, 1, 0.8]
o3d.visualization.draw_geometries([pcd],width=1200,height=1000)
法向量估计-目的:生成三维片面结构
import open3d as o3d
import numpy as np
print("Open3D read Point Cloud")
pcd = o3d.io.read_point_cloud(r"/Users/mac/Desktop/courses/ad/python/20211119/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)
使用command+或command-,可以缩放
三角片面生成
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"/Users/mac/Desktop/courses/ad/python/20211119/bunny10k.ply") #newrabbit.pcd")
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])
版权声明:本文为Tracywxy原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。