open3d点云配准函数registration_icp

open3d快速上手

基本原理

ICP, 即Iterative Closest Point, 迭代点算法。

ICP算法有多种形式,其中最简单的思路就是比较点与点之间的距离,对于点云 P = { p i } , Q = { q i } P=\{p_i\}, Q=\{q_i\} P={pi},Q={qi}而言,如果二者是同一目标,通过旋转、平移等操作可以实现重合的话,那么只需要固定 Q Q Q而不断地旋转或平移 P P P,最终二者一定能最完美地重合。

设旋转 P P P的矩阵为 R R R,平移矩阵为 t t t,在完美匹配的情况下,必有 q i = R p i + t q_i = Rp_i + t qi=Rpi+t

又因三维点云不具备栅格特征,故而很难保证 q i q_i qi p i p_i pi是同一点,所以要使得目标函数最小化

arg min ⁡ R , t 1 2 ∑ i = 1 n ∥ q i − R p i − t ∥ 2 \argmin_{R,t}\frac{1}{2}\sum^n_{i=1}\Vert q_i-Rp_i-t\Vert^2 R,targmin21i=1nqiRpit2

1992年Chen和Medioni对此方案进行了改进,提出了点对面的预估方法,其目标函数为

arg min ⁡ R , t 1 2 ∑ i = 1 n [ ( q i − R p i ) ⋅ n p ] 2 \argmin_{R,t}\frac{1}{2}\sum^n_{i=1}[(q_i-Rp_i)\cdot n_p]^2 R,targmin21i=1n[(qiRpi)np]2

其中 n p n_p np是点 p p p的法线,这种方案显然效率更高。

open3d调用

open3d中实现了ICP算法,参数如下

registration_icp(source, target, max_correspondence_distance, init, estimation_method, criteria)

source为点云 P P Ptarget为目标点云 Q Q Qmax_correspondence_distance为匹配点在未匹配时的最大距离,init为初始变化矩阵,默认为单位矩阵;criteria为精度。

estimation_method可以理解为上面提到的两种方案,下面选择点对点ICP方法进行计算

import numpy as np
import open3d as o3d

pipreg = o3d.pipelines.registration

pcd = o3d.data.DemoICPPointClouds()
src = o3d.io.read_point_cloud(pcd.paths[0])
tar = o3d.io.read_point_cloud(pcd.paths[1])
th = 0.02
trans_init = np.array([
    [0.862, 0.011, -0.507, 0.5], [-0.139, 0.967, -0.215, 0.7],
    [0.487, 0.255, 0.835, -1.4], [0.0, 0.0, 0.0, 1.0]])

reg = pipreg.registration_icp(
    src, tar, th, trans_init,
    pipreg.TransformationEstimationPointToPoint())

print(reg.transformation)
''' 变换矩阵
[[ 0.83924644  0.01006041 -0.54390867  0.64639961]
 [-0.15102344  0.96521988 -0.21491604  0.75166079]
 [ 0.52191123  0.2616952   0.81146378 -1.50303533]
 [ 0.          0.          0.          1.        ]]
'''
print(reg)

print(reg)的返回信息如下,表示点云配准的拟合程度

RegistrationResult with fitness=3.724495e-01, inlier_rmse=7.760179e-03, and correspondence_set size of 74056 Access transformation to get result.

绘图

为了对比配准前后的区别,对srctar放在图中对比

import copy
srcDraw = copy.deepcopy(src)
tarDraw = copy.deepcopy(tar)
srcDraw.paint_uniform_color([1, 1, 0])
tarDraw.paint_uniform_color([0, 1, 1])
srcDraw.transform(tf)
o3d.visualization.draw_geometries([srcDraw, tarDraw])

此为原图,可以看到两组点云完全是错位的

在这里插入图片描述

srcDraw = copy.deepcopy(src)
tarDraw.paint_uniform_color([0, 1, 1])
srcDraw.transform(reg.transformation)
o3d.visualization.draw_geometries([srcDraw, tarDraw])

得到结果如下,可见两组不同颜色的点云已经几乎重合到了一起

在这里插入图片描述

### Open3D 点云精确方法 #### ICP算法简介 点云是三维重建和计算机视觉领域的重要任务,旨在将多个点云数据集对齐至同一坐标系中。Iterative Closest Point (ICP) 是一种广泛使用的迭代最近点匹算法,能够实现高精度的点云[^1]。 #### 使用Open3D库执行ICP的具体过程 为了利用Open3D进行ICP操作,可以按照以下方式编写Python脚本: ```python import open3d as o3d def icp_registration(source_cloud, target_cloud, threshold, trans_init): # 执行ICP reg_p2p = o3d.pipelines.registration.registration_icp( source_cloud, target_cloud, threshold, trans_init, o3d.pipelines.registration.TransformationEstimationPointToPoint() ) return reg_p2p.transformation ``` 此函数接收源点云`source_cloud`、目标点云`target_cloud`以及初始变换矩阵`trans_init`作为输入参数,并返回最终计算所得的最佳变换矩阵。 #### SVD算法详解 对于更复杂的场景,SVD(奇异值分解)可用于求解最优旋转和平移矩阵,从而最小化两组对应点间的欧氏距离之平方和。该技术特别适用于已知部分或全部对应关系的情况,在此基础上进一步优化效果[^3]。 #### 结合其他预处理步骤提升确性 除了上述提到的方法外,还可以考虑先通过PCA或其他粗手段初步调整姿态差异较大的点云位置后再应用精细流程;或者采用基于特征描述子如FPFH来增强鲁棒性和效率,进而提高整体质量[^4]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

微小冷

请我喝杯咖啡

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

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

打赏作者

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

抵扣说明:

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

余额充值