可视化接口
API
open3d.visualization.draw_geometries(*args, **kwargs)
重载函数1
draw_geometries(geometry_list, window_name=’Open3D’, width=1920, height=1080, left=50, top=50, point_show_normal=False, mesh_show_wireframe=False, mesh_show_back_face=False)
- geometry_list:待显示的所有实体组成的列表
- window_name=‘Open3D’ :命名窗体
- width=1920 :窗体宽度
- height=1080 :窗体高度
- left=50 :左边缘宽度
- top=50, :上边缘宽度
- point_show_normal=False :是否显示法向
- mesh_show_wireframe=False:是否可视化网格线框
- mesh_show_back_face=False:是否可视化三角网格背面
重载函数2
draw_geometries(geometry_list, window_name=’Open3D’, width=1920, height=1080, left=50, top=50, point_show_normal=False, mesh_show_wireframe=False, mesh_show_back_face=False, lookat, up, front, zoom)
- lookat:摄影机的注视向量
- up:相机的上方向量
- front:摄影机的前向量
- zoom:相机的缩放系数
键盘鼠标操作
- 旋转: 鼠标左键拖动
- 平移: 鼠标中键拖动/ Ctrl+左键拖动
- 放大、缩小:鼠标滚轮
- 重置视点:R
- 记录视点、恢复视点:Ctrl+C, Ctrl+V
- 根据x轴坐标大小渲染:2
- 更改colormap:shift+0-4
- 退出:Q
- 帮助: H(最重要)
import open3d as o3d
import numpy as np
if __name__ == '__main__':
ply = o3d.io.read_point_cloud('bunny10k.ply', 'auto', True, True)
o3d.visualization.draw_geometries([ply],
window_name='Open3D',
width=1920, height=1080,
point_show_normal=False)
设置颜色
paint_uniform_color(self, color)
- 归一化RGB颜色,值的范围在[0,1]之间,所有点同色;
import open3d as o3d
import numpy as np
if __name__ == '__main__':
ply = o3d.io.read_point_cloud('bunny10k.ply', 'auto', True, True)
ply.paint_uniform_color([0, 0, 1])
#ply.paint_uniform_color([1, 0, 1])
# ply.paint_uniform_color([1, 0, 0])
o3d.visualization.draw_geometries([ply],
window_name='Open3D',
width=1920, height=1080,
point_show_normal=False)
设置索引点颜色
import open3d as o3d
import numpy as np
if __name__ == '__main__':
ply = o3d.io.read_point_cloud('bunny10k.ply', 'auto', True, True)
ply.paint_uniform_color([0, 0, 1])
color=np.array(ply.colors)
inlier=[i for i in range(0,color.shape[0]) if i % 2==0]
color[inlier]=[1,0,0]
ply.colors=o3d.utility.Vector3dVector(color[:, :3])
o3d.visualization.draw_geometries([ply],
window_name='Open3D',
width=1920, height=1080,
point_show_normal=False)
可视化法线
estimate_normals(self, search_param=KDTreeSearchParamKNN with knn = 30, fast_normal_computation=True)
import open3d as o3d
import numpy as np
if __name__ == '__main__':
ply = o3d.io.read_point_cloud('bunny10k.ply', 'auto', True, True)
ply.paint_uniform_color([0, 0, 1])
# 计算法线,搜索半径0.01m,只考虑邻域内的30个点
ply.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.01, max_nn=30))
o3d.visualization.draw_geometries([ply],window_name="Open3D", width=1920, height=1080,left=50, top=50,point_show_normal=True )
隐藏点移除
hidden_point_removal(self, camera_location, radius)
- 移除点云中的隐藏点并返回剩余点的网格;
- camera_location (numpy.ndarray[float64[3, 1]]): 所有在那个位置看不见的地点都会被移除;
- radius (float): 球投影的半径
import open3d as o3d
import numpy as np
pcd = o3d.io.read_point_cloud("bunny10k.ply")
_, pt_map = pcd.hidden_point_removal([0,0,0.5], 25)
pcd = pcd.select_by_index(pt_map)
o3d.visualization.draw_geometries([pcd])
可视化界面设置
- 背景颜色
- 坐标系
- 点云大小等
import open3d as o3d
import numpy as np
pcd = o3d.io.read_point_cloud('bunny10k.ply')
#可视化句柄
viewer = o3d.visualization.Visualizer()
viewer.create_window(window_name='可视化', width=1920, height=1080)
#界面参数选项
opt = viewer.get_render_option()
#背景颜色
opt.background_color = np.asarray([0, 1, 0])
#点大小
opt.point_size = 1
#添加坐标系
opt.show_coordinate_frame = True
#颜色
pcd.paint_uniform_color([1, 0, 0])
viewer.add_geometry(pcd)
#激活界面循环
viewer.run()
viewer.destroy_window()