Opene3d提供了一个方便的可视化函数draw_geometries,他接受一组几何对象(PointCloud,TriangleMesh或者Image),并且一起渲染他们。我们在可视化界面提供了许多功能,例如通过鼠标的缩放,旋转和平移,改变渲染风格和屏幕截图。在窗口界面按 h 打印出全部的函数列表。 print("Load a ply point cloud, print it, and render it") pcd = o3d.io.read_point_cloud("../../TestData/fragment.ply") o3d.visualization.draw_geometries([pcd], zoom=0.3412, front=[0.4257, -0.2125, -0.8795], lookat=[2.6172, 2.0475, 1.532], up=[-0.0694, -0.9768, 0.2024]) Note:在一些操作系统(比如OS X ),可视化窗口可能不响应键盘输入。这通常是因为控制台保持了输入焦点,而不是将其传递给可视化窗口。运行pythonw而不是python来解决这个问题。 Note:除了draw_geometries,Open3d还设置了一系列更高级别的兄弟函数(sibling functions)。draw_geometries_with_custom_animation允许程序员去自定义动画轨迹并且在GUI中播放。draw_geometries_with_animation_callback和draw_geometries_with_key_callback接受python的回调函数作为输入。回调函数在自动动画循环或按键事件中有用。更多细节请看Customized visualization。 在一开始,点云的渲染是颠倒的。 在使用鼠标左键拖动了之后,我们可以得到一个更好的视角。 按下ctrl+c保持这个视角后,这个视角将会成为一个保存在粘贴板里面的一个json字符串。这时我们再旋转视图到一个不同的视角,比如: Open3d可视化支持多种渲染风格。比如按 1 将在Phong lighting 和简单颜色渲染之间切换(simple color rendering)。按 2 将展现基于x坐标的颜色。 颜色映射也可以调整,比如使用shift+4,就可以把颜色从喷墨映射调整到热图映射。 下面的代码使用 create_mesh_cubic , create_mesh_sphere和create_mesh_cylinder去创造一个立方体,一个球和一个圆柱体。立方体被涂成红色,球被涂成蓝色,圆柱被涂成绿色。为两个网格去计算法线来支持Phong shading(请看Visualize 3D mesh 和 Surface normal estimation。我们在这里使用了create_mesh_coordinate_frame去创造了一个原点在(-2,-2,-2)的坐标轴。 print("Let's define some primitives") mesh_box = o3d.geometry.TriangleMesh.create_box(width=1.0, height=1.0, depth=1.0) mesh_box.compute_vertex_normals() mesh_box.paint_uniform_color([0.9, 0.1, 0.1]) mesh_sphere = o3d.geometry.TriangleMesh.create_sphere(radius=1.0) mesh_sphere.compute_vertex_normals() mesh_sphere.paint_uniform_color([0.1, 0.1, 0.7]) mesh_cylinder = o3d.geometry.TriangleMesh.create_cylinder(radius=0.3, height=4.0) mesh_cylinder.compute_vertex_normals() mesh_cylinder.paint_uniform_color([0.1, 0.9, 0.1]) mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame( size=0.6, origin=[-2, -2, -2]) draw_geometries支持多个几何图形一起可视化。另外,TriangleMesh支持使用 + 操作符来将多个几何图形拼接成一个。我们推荐第一种方式,因为它支持多种不同的几何类型一起可视化(比如点云和网格是可以一起被可视化的)。 print("We draw a few primitives using collection.") o3d.visualization.draw_geometries( [mesh_box, mesh_sphere, mesh_cylinder, mesh_frame]) print("We draw a few primitives using + operator of mesh.") o3d.visualization.draw_geometries( [mesh_box + mesh_sphere + mesh_cylinder + mesh_frame]) We draw a few primitives using collection. We draw a few primitives using + operator of mesh. 要画线的话,需要定义Lineset和创造一组点还有一组边。边是一对点的索引。下面的例子中创建了自定义的点和边(表示为线(lines))来创建一个立方体。颜色是可选的,在这个例子中每条边表示为红色。这个脚本可视化的下面的立方体。 print("Let's draw a cubic using o3d.geometry.LineSet.") points = [ [0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1], [1, 0, 1], [0, 1, 1], [1, 1, 1], ] lines = [ [0, 1], [0, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 7], [6, 7], [0, 4], [1, 5], [2, 6], [3, 7], ] colors = [[1, 0, 0] for i in range(len(lines))] line_set = o3d.geometry.LineSet( points=o3d.utility.Vector3dVector(points), lines=o3d.utility.Vector2iVector(lines), ) line_set.colors = o3d.utility.Vector3dVector(colors) o3d.visualization.draw_geometries([line_set], zoom=0.8) Let’s draw a cubic using o3d.geometry.LineSet. |
|