当前位置:   article > 正文

Open3d学习计划——8(可视化)_draw_geometries

draw_geometries

Open3d学习计划——8(可视化)

欢迎大家关注“点云PCL”公众号,进入群聊一起学习。

draw_geometries函数

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])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Load a ply point cloud, print it, and render it

在这里插入图片描述

– Mouse view control –
Left button + drag : Rotate.
Ctrl + left button + drag : Translate.
Wheel button + drag : Translate.
Shift + left button + drag : Roll.
Wheel : Zoom in/out.
– Keyboard view control –
[/] : Increase/decrease field of view.
R : Reset view point.
Ctrl/Cmd + C : Copy current view status into the clipboard.
Ctrl/Cmd + V : Paste view status from clipboard.
– General control –
Q, Esc : Exit window.
H : Print help message.
P, PrtScn : Take a screen capture.
D : Take a depth capture.
O : Take a capture of current rendering settings.

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字符串。这时我们再旋转视图到一个不同的视角,比如:
在这里插入图片描述
这时候使用ctrl+v,就可以回到原始视角。
在这里插入图片描述

渲染风格

Open3d可视化支持多种渲染风格。比如按 1 将在Phong lighting 和简单颜色渲染之间切换(simple color rendering)。按 2 将展现基于x坐标的颜色。
在这里插入图片描述
颜色映射也可以调整,比如使用shift+4,就可以把颜色从喷墨映射调整到热图映射。
在这里插入图片描述

几何基元(Geometry primitives)

下面的代码使用 create_mesh_cubic , create_mesh_sphere和create_mesh_cylinder去创造一个立方体,一个球和一个圆柱体。立方体被涂成红色,球被涂成蓝色,圆柱被涂成绿色。为两个网格去计算法线来支持Phong shading(请看Visualize 3D meshSurface 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])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

Let’s define some primitives

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])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

Let’s draw a cubic using o3d.geometry.LineSet.

在这里插入图片描述

关于翻译大家有更好的意见欢迎评论一起学习!!!

欢迎大家加入知识星球一起学习。

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/95556
推荐阅读
相关标签
  

闽ICP备14008679号