pcl中ICP算法可以对两个3d点云进行匹配,在实际应用过程中,有时候需要对2d点云进行匹配,虽然也可以将2d点云保存为3d点云,再使用ICP进行匹配,但匹配过程引入了不必要的自由度,会导致计算速度变慢或者匹配错误。
根据上一篇博客可知,ICP在构造函数中会构造三个对象,其中transformation_estimation_定义了ICP最近点匹配后计算变换矩阵的方法,默认采用SVD分解计算,如下所示:
transformation_estimation_.reset (new pcl::registration::TransformationEstimationSVD<PointSource, PointTarget, Scalar> ());
而这个transformation_estimation_对象时可以通过icp的setTransformationEstimation方法进行替换的,因此就想到pcl的registration文件夹中可能会存在其他transformation_estimation方法,结果真的发现了transformation_estimation_2D.h,这个文件中有TransformationEstimation2D类,是专门针对2d点云位姿估计的,可以构造TransformationEstimation2D的对象来替换icp默认的transformation_estimation_来实现2d的icp计算。调用的过程如下所示:
pcl::registration::TransformationEstimation2D<PointXYZ, PointXYZ>::Ptr
transform_estimation(new pcl::registration::TransformationEstimation2D<PointXYZ, PointXYZ>());
pcl::IterativeClosestPoint<PointXYZ, PointXYZ>::Ptr icp(new pcl::IterativeClosestPoint<PointXYZ, PointXYZ>());
icp_->setTransformationEstimation(transform_estimation);