本文主要是介绍第九次作业整理(open3d/20211119),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
三维空间建模
安装包-open3d
错误解决
多种点云方法
多角度点云拼接在一起生成整个点云
近邻搜索
混合搜索
法向量估计-目的:生成三维片面结构
三角片面生成
三维空间建模
三维空间什么都没有,摄像机视角即为人眼视角,默认材质近似纸张
安装包-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 npprint("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 npprint("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 npprint("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 npprint("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 npprint("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])
这篇关于第九次作业整理(open3d/20211119)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!