ICP(Iterative Closest Point迭代最近点)算法是一种点集对点集配准方法。在VTK、PCL、MRPT、MeshLab等C++库或软件中都有实现,可以参见维基百科中的ICP Algorithm Implementations.

  ICP算法采用最小二乘估计计算变换矩阵,原理简单且具有较好的精度,但是由于采用了迭代计算,导致算法计算速度较慢,而且采用ICP进行配准计算时,其对待配准点云的初始位置有一定要求,若所选初始位置不合理,则会导致算法陷入局部最优。PCL点云库已经实现了多种点云配准算法:

  IterativeClosestPoint类提供了标准ICP算法的实现(The transformation is estimated based on SVD),算法迭代结束条件有如下几个:

  1. 最大迭代次数:Number of iterations has reached the maximum user imposed number of iterations (via setMaximumIterations)
  2. 两次变化矩阵之间的差值:The epsilon (difference) between the previous transformation and the current estimated transformation is smaller than an user imposed value (via setTransformationEpsilon)
  3. 均方误差(MSE):The sum of Euclidean squared errors is smaller than a user defined threshold (via setEuclideanFitnessEpsilon)

  基本用法如下:

IterativeClosestPoint<PointXYZ, PointXYZ> icp;
// Set the input source and target
icp.setInputCloud (cloud_source);
icp.setInputTarget (cloud_target);
// Set the max correspondence distance to 5cm (e.g., correspondences with higher distances will be ignored)
icp.setMaxCorrespondenceDistance (0.05);
// Set the maximum number of iterations (criterion 1)
icp.setMaximumIterations ();
// Set the transformation epsilon (criterion 2)
icp.setTransformationEpsilon (1e-);
// Set the euclidean distance difference epsilon (criterion 3)
icp.setEuclideanFitnessEpsilon ();
// Perform the alignment
icp.align (cloud_source_registered);
// Obtain the transformation that aligned cloud_source to cloud_source_registered
Eigen::Matrix4f transformation = icp.getFinalTransformation ();

  下面是一个完整的例子:

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/icp.h> int main (int argc, char** argv)
{
//Creates two pcl::PointCloud<pcl::PointXYZ> boost shared pointers and initializes them
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out (new pcl::PointCloud<pcl::PointXYZ>); // Fill in the CloudIn data
cloud_in->width = ;
cloud_in->height = ;
cloud_in->is_dense = false;
cloud_in->points.resize (cloud_in->width * cloud_in->height);
for (size_t i = ; i < cloud_in->points.size (); ++i)
{
cloud_in->points[i].x = * rand () / (RAND_MAX + 1.0f);
cloud_in->points[i].y = * rand () / (RAND_MAX + 1.0f);
cloud_in->points[i].z = * rand () / (RAND_MAX + 1.0f);
} *cloud_out = *cloud_in; //performs a simple rigid transform on the point cloud
for (size_t i = ; i < cloud_in->points.size (); ++i)
cloud_out->points[i].x = cloud_in->points[i].x + 1.5f; //creates an instance of an IterativeClosestPoint and gives it some useful information
pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
icp.setInputCloud(cloud_in);
icp.setInputTarget(cloud_out); //Creates a pcl::PointCloud<pcl::PointXYZ> to which the IterativeClosestPoint can save the resultant cloud after applying the algorithm
pcl::PointCloud<pcl::PointXYZ> Final; //Call the registration algorithm which estimates the transformation and returns the transformed source (input) as output.
icp.align(Final); //Return the state of convergence after the last align run.
//If the two PointClouds align correctly then icp.hasConverged() = 1 (true).
std::cout << "has converged: " << icp.hasConverged() <<std::endl; //Obtain the Euclidean fitness score (e.g., sum of squared distances from the source to the target)
std::cout << "score: " <<icp.getFitnessScore() << std::endl;
std::cout << "----------------------------------------------------------"<< std::endl; //Get the final transformation matrix estimated by the registration method.
std::cout << icp.getFinalTransformation() << std::endl; return ();
}

  结果如下,ICP算法计算出了正确的变换

  在PCL官方的tutorial中还有个ICP算法交互的例子(Interactive Iterative Closest Point,网站上该例子的源代码编译时有一点问题需要修改...),该程序中按一次空格ICP迭代计算一次。可以看出,随着迭代进行,两块点云逐渐重合在一起。

参考:

How to use iterative closest point

http://pointclouds.org/documentation/tutorials/iterative_closest_point.php#iterative-closest-point

Interactive Iterative Closest Point

http://pointclouds.org/documentation/tutorials/interactive_icp.php#interactive-icp

PCL之ICP算法实现

https://segmentfault.com/a/1190000005930422

PCL学习笔记二:Registration (ICP算法)

http://blog.csdn.net/u010696366/article/details/8941938

PCL点云库:ICP算法的更多相关文章

  1. PCL点云库中的坐标系(CoordinateSystem)

    博客转载自:https://blog.csdn.net/qq_33624918/article/details/80488590 引言 世上本没有坐标系,用的人多了,便定义了坐标系统用来定位.地理坐标 ...

  2. Windows下安装PCL点云库

    原文链接:http://blog.csdn.net/u012337034/article/details/38270109 简介:         在Windows下安装PCL点云库的方法大概有两种: ...

  3. Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境

    Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境 下载PCL For windows 软件包 到这个网站下载PCL-All-In-One Installer: ...

  4. PCL点云库(Point Cloud Library)简介

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=29 什么是PCL PCL(Point Cloud Library)是在吸收了 ...

  5. python利用pybind11调用PCL点云库

    2019年7月9日14:31:13 完成了一个简单的小例子,python生成点云数据,利用pybind11传给PCL显示. ubuntu 16.04 + Anaconda3  python3.6 + ...

  6. PCL点云库:对点云进行变换(Using a matrix to transform a point cloud)

    点云数据可以用ASCII码的形式存储在PCD文件中(关于该格式的描述可以参考链接:The PCD (Point Cloud Data) file format).为了生成三维点云数据,在excel中用 ...

  7. [PCL]1 PCL点云库安装

    1.安装文件下载:官网,我还是比较喜欢别人编译好的安装包啊,哈哈. http://www.pointclouds.org/downloads/windows.html 2.傻瓜式安装(下面的依赖项都集 ...

  8. PCL点云库增加自定义数据类型

    #include <pcl/filters/passthrough.h> #include <pcl/filters/impl/passthrough.hpp> // the ...

  9. 25 面向对象设计实例——基于PCL点云库的通用工具开发

    0 引言 问题背景:pcl中提供了大量工具,用于对点云和三角面片文件进行处理和显示.在研究中,存在很多简易的需求,比如点云坐标转换,点云的打开显示以及同步显示,点云的最小包络求解,点云的格式转换等等. ...

随机推荐

  1. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  2. RMQ(非log2储存方法)

    2016-03-31 RMQ 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 长度为n的数列A,以及q个询问,每次询问一段区间 ...

  3. protocolbuffe

    protocolbuffer(以下简称PB)是google 的一种数据交换的格式,它独立于语言,独立于平台.google 提供了多种语言的实现:java.c#.c++.go 和 python,每一种实 ...

  4. 161102、MyBatis中批量插入

    方法一: <insert id="insertbatch" parameterType="java.util.List"> <selectKe ...

  5. Linux系统中“动态库”和“静态库”那点事儿【转】

    转自:http://blog.chinaunix.net/uid-23069658-id-3142046.html 今天我们主要来说说Linux系统下基于动态库(.so)和静态(.a)的程序那些猫腻. ...

  6. java继承关系中成员变量,构造方法,成员方法的关系

    Java继承中的成员关系 A:成员变量 a:子类的成员变量名称和父类中的成员变量名称不一样,这个太简单写那个名字就访问那个名字! b:子类的成员变量名称和父类中的成员变量名称一样,这个怎么访问呢? 子 ...

  7. NIOS II CPU复位异常的原因及解决方案

    NIOS II CPU复位异常的原因及解决方案   近期在用nios ii做项目时,发现一个奇怪的现象,在NIOS II EDS软件中编写好的代码,烧写到芯片中,第一次能够正常运行,但是当我按下板卡上 ...

  8. umask:遮罩码

    查看umask:umask 创建文件:-umask 文件默认不能具有执行权限 创建目录:-umask 设置umask:umask 0022 生效访范围:当前shell

  9. php curl应该怎么使用呢

    原php默认并不进行此项功能的扩展,但还是有的,只是没有让它生效罢了.打开PHP安装目录,搜索以下三个文件 ssleay32.dll.libeay32.dll和 php_ curl .dll,一一拷贝 ...

  10. IOS中用UIStoryBoard类初始化/跳转控制器

    1.空工程中通过创建storyboard文件加载页面   //获取Main.storyboardUIStoryboard *mainStory = [UIStoryboard storyboardWi ...