迭代最近点(ICP)进行点云配准

ICP算法原理

这部分在很多博客中有说明,这里不加以复述,提供几个博客链接,有兴趣者请自行研究,本文主要介绍如何使用PCL中的ICP算法。不了解PCL库的请看链接。
参考资料1:关于配准问题
参考资料2:ICP基本原理

PCL中ICP算法使用详解

pcl中实现了ICP算法类 IterativeClosestPoint,也提供了关于该类的使用教程DEMO,但不够具体,下面对其做写补充:
几个主要的设置:
1. setInputCloud (cloud_source) 设置原始点云
2. setInputTarget (cloud_target) 设置目标点云
3. setMaxCorrespondenceDistance() 设置最大对应点的欧式距离,只有对应点之间的距离小于该设置值的对应点才作为ICP计算的点对。默认值为:1.7976931348623157e+308,基本上对所有点都计算了匹配点。
4. 三个迭代终止条件设置:
1) setMaximumIterations() 设置最大的迭代次数。迭代停止条件之一
2) setTransformationEpsilon() 设置前后两次迭代的转换矩阵的最大容差(epsilion),一旦两次迭代小于这个最大容差,则认为已经收敛到最优解,迭代停止。迭代停止条件之二,默认值为:0
3) setEuclideanFitnessEpsilon() 设置前后两次迭代的点对的欧式距离均值的最大容差,迭代终止条件之三,默认值为:-std::numeric_limits::max ()
迭代满足上述任一条件,终止迭代。原文如下:

      * ConvergenceCriteria, and implements the following criteria for registration loop
      * evaluation:
      *
      *  * a maximum number of iterations has been reached
      *  * the transformation (R, t) cannot be further updated (the difference between current and previous is smaller than a threshold)
      *  * the Mean Squared Error (MSE) between the current set of correspondences and the previous one is smaller than some threshold (both relative and absolute tests)
      *
      * \note Convergence is considered reached if ANY of the above criteria are met.

5.getFinalTransformation () 获取最终的配准的转化矩阵,即原始点云到目标点云的刚体变换,返回Matrix4数据类型,该数据类型采用了另一个专门用于矩阵计算的开源c++库eigen
6. align (PointCloudSource &output) 进行ICP配准,输出变换后点云
7. hasConverged() 获取收敛状态,注意,只要迭代过程符合上述三个终止条件之一,该函数返回true。
8. min_number_correspondences_ 最小匹配点对数量,默认值为3,即由空间中的非共线的三点就能确定刚体变换,建议将该值设置大点,否则容易出现错误匹配。
9. 最终迭代终止的原因可从convergence_criteria_变量中获取,

  1. getFitnessScore()用于获取迭代结束后目标点云和配准后的点云的最近点之间距离的均值。
    值得注意的是,在PCL中,通常以两点之间的欧式距离的平方作为两点之间的距离,之所以这样设置,是为了省掉开根号计算,开根号计算是很费时的操作。

使用案例

main.cpp

#include "PointCloudProcess.hpp"
#include <pcl/console/time.h>   
int main(int argc, char *argv[])
{
    //icp匹配实验
#if 1
    pcl::console::TicToc time;
    resolution = 0.0009338;
    cv::Scalar color = cv::Scalar(0, 255, 0);
    pcl::visualization::PCLVisualizer viewer("ICP demo");
    pcl::PointCloud<PointType>::Ptr pcloud_ori(new pcl::PointCloud<PointType>()); 
    pcl::PointCloud<PointType>::Ptr pcloud_source(new pcl::PointCloud<PointType>());
    pcl::PointCloud<PointType>::Ptr pcloud_targ
  • 8
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
ICP (Iterative Closest Point) 算法是一种常用的点云配准技术,尤其适用于三维空间中的物体对齐。在Python中,有很多支持ICP算法,其中比较流行的是`pcl-python`(Point Cloud Library for Python)和`open3d`。 `pcl-python`提供了完整的点云处理工具集,其中包括了ICP算法的实现。你可以用它来执行点云配准,如以下代码示例所示: ```python from pcl import pcl_io, cloud_compression, pcl_common import numpy as np # 加载两个点云 pc1 = pcl.io.read_point_cloud_ascii("pointcloud1.txt") pc2 = pcl.io.read_point_cloud_ascii("pointcloud2.txt") # 创建ICP对象并设置初始参数 icp = cloud_compression.icp_registration() icp.set_transformation_model(pcl.icp.TRANSLATION) # 运行ICP算法 Transformation, distance_threshold = icp.register(pc1, pc2) # 应用变换到第二个点云 transformed_pc2 = icp.transform(pc2, Transformation) ``` `open3d`也是一个强大的3D可视化和操作,也包含ICP功能。例如,你可以这样调用它的` registration_icp `函数: ```python import open3d as o3d pc1 = o3d.io.read_point_cloud("pointcloud1.pcd") pc2 = o3d.io.read_point_cloud("pointcloud2.pcd") # 初始化配准器 reg = o3d.registration.registration_icp( source=pc1, target=pc2, init_transform=o3d.Transform(), max_correspondence_distance=0.1, # 设置匹配距离阈值 criteria=o3d.registration.ICPConvergenceCriteria(max_iteration=100) # 设置迭代次数 ) aligned_pc2 = reg.transformed_source # 获取配准后的目标点云 ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值