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

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])

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])

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])

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.

在这里插入图片描述

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

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

在这里插入图片描述

open3d是一个用于处理三维数据(点云、三维模型等)的开源库。点云配准是将两个或多个点云数据进行对齐的过程,以便在一个全局坐标系下进行比较、分析或重建。其中,四元数法是一种常用的点云配准方法。 四元数是一种用四个实数表示的扩充复数,可以用于描述旋转变换。在点云配准中,使用四元数法是因为其具有以下优势: 第一,四元数具有紧凑的表示形式,只需要四个实数即可表示旋转变换,相较于旋转矩阵的九个实数表示方式节省了存储空间,降低了计算复杂度。 第二,四元数法能够有效地避免了“万向锁”问题。万向锁是指在使用欧拉角进行坐标变换时,由于旋转过程中会出现奇点,导致旋转角度无法精确表示的问题。而四元数法不会出现这个问题,具有更好的数值稳定性。 在open3d中,点云配准的四元数法通常有以下几个步骤: 首先,计算两个点云之间的特征描述子,例如FPFH(Fast Point Feature Histograms)或SHOT(Signature of Histograms of Orientations)。这些描述子能够表示点云的局部几何信息。 然后,根据特征描述子的相似性,寻找初始的点对应关系。 接下来,通过最小化点云之间的误差指标,例如最小化点到平面的距离或最小化点到点的距离,来优化点对应关系,并计算出旋转矩阵。 将旋转矩阵转换为四元数表示,即可完成点云的配准过程。 四元数法是open3d中常用的点云配准方法之一,其能够高效地实现点云的准确对齐。
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值