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. 《zw版·Halcon-delphi系列原创教程》 水果自动分类脚本(机器学习、人工智能)

    <zw版·Halcon-delphi系列原创教程> 水果自动分类脚本(机器学习.人工智能) 前面介绍了超市,流水线,酸奶的自动分类算法,下面再介绍一个水果的自动分类算法. Halcon强大 ...

  2. Debian类系统必做——将【你的用户】加入sudoers用户组

    切换到root:su root   修改sudoers nano /etc/sudoers 在root    ALL=(ALL:ALL) ALL下,加入:liz        ALL=(ALL:ALL ...

  3. 「Ruby && Sqlite3」How to install sqlite3 for ruby? (solve: sqlite-ruby no such file...)

    error message:           no such file .... 安装 gem install sqlite3-ruby -- --with-sqlite3-dir=/usr/lo ...

  4. COM编程之四 引用计数

    [1]客户为什么不应直接控制组件的生命期? 假设一个组件A正在使用另一个组件B,可想组件A(客户)代码中肯定有若干个指向组件B接口的指针. 那么这种情况下,当使用完一个接口而仍然在使用另一个接口时,是 ...

  5. Java常见编码方式简介

    计算机只能识别二进制数据,早期由来是电信号. 为了方便应用计算机,让它可以识别各个国家的文字. 就将各个国家的文字用数字来表示,并一一对应,形成一张表. ASCII:美国标准信息交换码. 用一个字节的 ...

  6. [转]Jexus的常用操作和基本配置

    转自http://www.cnblogs.com/xiaodiejinghong/archive/2013/04/05/3000404.html 3.Jexus的操作 经过两个章节关于Jexus的介绍 ...

  7. Linux下查看用户列表

    cat /etc/passwd 可以查看所有用户的列表 w 可以查看当前活跃的用户列表 cat /etc/group 查看用户组

  8. linux命令:du 命令

    Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...

  9. JavaScript脚本语言基础(三)

    导读: 数学对象(Math) 数组对象(Array) 字符串对象(String) 日期对象(Date) js对象是属性和方法的集合.JavaScript中的所有事物都是对象,如:字符串.数值.数组.函 ...

  10. [BIM]案例

    以下是中建三局BIM小组的项目,用以参考: BIM协同设计与质量控制 现实建筑物实体都是以三维空间状态存在,若用三维设计表达更具有优势.如复杂管综设计,一般情况下,二维AutoCAD设计是在建筑.结构 ...