【点云处理技术之open3d】第二篇:点云的基本操作篇——可视化、降采样、法向量、裁剪和绘制点云


下面分别介绍open3d的点云基本操作: 可视化、降采样、法向量、裁剪和绘制点云。首先会统一给出代码和注释,然后分别对这些基本操作进行一一解释。

0. 代码解释

import open3d as o3d
import numpy as np

#*******************************点云的可视化***********************************

pcd = o3d.io.read_point_cloud("../test_data/fragment.ply") # 读取ply或者pcd文件

print(pcd) # 点云简单信息 》》PointCloud with 113662 points.
# print(np.asarray(pcd.points)) #打印点云

# 可视化点云
o3d.visualization.draw_geometries([pcd])

#*******************************点云降采样***********************************

print("Downsample the point cloud with a voxel of 0.05")
downpcd = pcd.voxel_down_sample(voxel_size=0.05)
o3d.visualization.draw_geometries([downpcd],
                                  zoom=0.3412,
                                  front=[0.4257, -0.2125, -0.8795],
                                  lookat=[2.6172, 2.0475, 1.532],
                                  up=[-0.0694, -0.9768, 0.2024])

#*******************************顶点法线估计***********************************
#重新计算,一般可视化操作都带有法线估计(可以不用重新计算)
print("Recompute the normal of the downsampled point cloud")
downpcd.estimate_normals(
    search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.1, max_nn=30))
o3d.visualization.draw_geometries([downpcd],
                                  zoom=0.3412,
                                  front=[0.4257, -0.2125, -0.8795],
                                  lookat=[2.6172, 2.0475, 1.532],
                                  up=[-0.0694, -0.9768, 0.2024],
                                  point_show_normal=True)

#*******************************访问顶点的法线***********************************
print("Print a normal vector of the 0th point")
print(downpcd.normals[0]) #打印第0个顶点的法线

# 打印10个点的法线估计
print("Print the normal vectors of the first 10 points")
print(np.asarray(downpcd.normals)[:10, :])

#*******************************点云的裁剪***********************************
print("Load a polygon volume and use it to crop the original point cloud")
vol = o3d.visualization.read_selection_polygon_volume(
    "../test_data/Crop/cropped.json")
chair = vol.crop_point_cloud(pcd)
o3d.visualization.draw_geometries([chair],
                                  zoom=0.7,
                                  front=[0.5439, -0.2333, -0.8060],
                                  lookat=[2.4615, 2.1331, 1.338],
                                  up=[-0.1781, -0.9708, 0.1608])

#*******************************画点云***********************************                                
print("Paint chair")
chair.paint_uniform_color([1, 0.706, 0]) #给点云统一绘制颜色,RGB范围[0,1]
o3d.visualization.draw_geometries([chair],
                                  zoom=0.7,
                                  front=[0.5439, -0.2333, -0.8060],
                                  lookat=[2.4615, 2.1331, 1.338],
                                  up=[-0.1781, -0.9708, 0.1608])

1. 可视化点云

可视化点云如下:
在这里插入图片描述

按H键盘,可以输出一些常用的操作,如下所示。

[Open3D INFO]   -- Mouse view control --
[Open3D INFO]     Left button + drag         : Rotate.
[Open3D INFO]     Ctrl + left button + drag  : Translate.
[Open3D INFO]     Wheel button + drag        : Translate.
[Open3D INFO]     Shift + left button + drag : Roll.
[Open3D INFO]     Wheel                      : Zoom in/out.
[Open3D INFO] 
[Open3D INFO]   -- Keyboard view control --
[Open3D INFO]     [/]          : Increase/decrease field of view.
[Open3D INFO]     R            : Reset view point.
[Open3D INFO]     Ctrl/Cmd + C : Copy current view status into the clipboard.
[Open3D INFO]     Ctrl/Cmd + V : Paste view status from clipboard.
...

2. 点云的降采样

open3d的降采样方法步骤为:

  1. 首先将点云体素化
  2. 用体素中所有点的平均值替代体素中的值

降采样效果如下:
在这里插入图片描述

3. 顶点的法线估计

求顶点的法线估计是点云的基础操作。按N可以关闭或可视化法线。-和+分别缩短和延长法线长度。

一般可视化操作都带有法线估计(可以不用重新计算)。

法线估计的可视化效果如下:

在这里插入图片描述

radius = 0.1 和 max_nn = 30分别表示搜索半径和最大最近邻。所以它表示搜索半径为10cm,最多只考虑30个近领域点进行估计。

4. 访问顶点的法线

代码中第0个点的法线为:

Print a normal vector of the 0th point
[-0.21838377 -0.94240442 -0.25334252]
Print the normal vectors of the first 10 points
[[-0.21838377 -0.94240442 -0.25334252]
 [-0.39147152 -0.43746664 -0.8095511 ]
 [-0.00694405 -0.99478075 -0.10179902]
 [-0.00399871 -0.99965423 -0.02598917]
 [-0.93768261 -0.07378998  0.3395679 ]
 [-0.43476205 -0.62438493 -0.64894177]
 [-0.09739809 -0.9928602  -0.06886388]
 [-0.11728718 -0.95516445 -0.27185399]
 [-0.01038945 -0.99968858 -0.02268921]
 [-0.00816546 -0.99965616 -0.02491762]]

5. 点云的裁剪

先读取json文件,通过json文件的polygon裁剪点云。
在这里插入图片描述

6. 绘制点云

paint_uniform_color表示给点云统一绘制颜色,RGB颜色范围为[0,1]。
在这里插入图片描述

  • 0
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

非晚非晚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值