Open3d(进阶二)——彩色点云配准

 亲测代码程序可运行使用,open3d版本0.13.0。

open3d数据资源下载:GitHub - Cobotic/Open3D: Open3D: A Modern Library for 3D Data Processing

代码执行功能有:可视化函数、输入点云、point-to-plane ICP、彩色点云配准,详情请见代码。

'''
Author: dongcidaci
Date: 2021-09-13 15:49:49
LastEditTime: 2021-09-13 16:03:58
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \open3d_code\test_data\02_2_caisepeizhun.py
'''
import open3d as o3d
import numpy as np
import copy
#彩色点云配准
#演示了一种同时使用几何和颜色进行配准的ICP变体
#实现了颜色信息锁定与切平面的对齐

#可视化函数
#为了掩饰不同颜色点云之间的对齐,draw_registration_result_original_color使用原本的颜色可视化源点云.
def draw_registration_result_original_color(source, target, transformation):
    source_temp = copy.deepcopy(source)
    source_temp.transform(transformation)
    o3d.visualization.draw_geometries([source_temp, target])

#输入
#从两个文件中读取源点云和目标点云.使用单位阵作为初始化的配准矩阵.
print("1. Load two point clouds and show initial pose")
source = o3d.io.read_point_cloud("test_data/ColoredICP/frag_115.ply")
target = o3d.io.read_point_cloud("test_data/ColoredICP/frag_116.ply")
# draw initial alignment
current_transformation = np.identity(4)
draw_registration_result_original_color(source, target, current_transformation)

#Point-to-plane ICP
#下面的可视化结果展示了未对其的绿色三角形纹理.这是因为几何约束不能够阻止两个平面滑动.

# point to plane ICP
current_transformation = np.identity(4)
print("2. Point-to-plane ICP registration is applied on original point")
print("   clouds to refine the alignment. Distance threshold 0.02.")
result_icp = o3d.pipelines.registration.registration_icp(
        source, target, 0.02, current_transformation,
        o3d.pipelines.registration.TransformationEstimationPointToPlane())
print(result_icp)
draw_registration_result_original_color(source, target, result_icp.transformation)

#彩色点云配准
#彩色点云配准的核心函数是 registration_colored_icp .
voxel_radius = [0.04, 0.02, 0.01]
max_iter = [50, 30, 14]
current_transformation = np.identity(4)
print("3. Colored point cloud registration")
for scale in range(3):
    iter = max_iter[scale]
    radius = voxel_radius[scale]
    print([iter, radius, scale])

    print("3-1. Downsample with a voxel size %.2f" % radius)
    source_down = source.voxel_down_sample(radius)
    target_down = target.voxel_down_sample(radius)

    print("3-2. Estimate normal.")
    source_down.estimate_normals(
        o3d.geometry.KDTreeSearchParamHybrid(radius=radius * 2, max_nn=30))
    target_down.estimate_normals(
        o3d.geometry.KDTreeSearchParamHybrid(radius=radius * 2, max_nn=30))

    print("3-3. Applying colored point cloud registration")
    result_icp = o3d.pipelines.registration.registration_colored_icp(
        source_down, target_down, radius, current_transformation,
        o3d.pipelines.registration.ICPConvergenceCriteria(relative_fitness=1e-6,
                                                relative_rmse=1e-6,
                                                max_iteration=iter))
    current_transformation = result_icp.transformation
    print(result_icp)
draw_registration_result_original_color(source, target, result_icp.transformation)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值