PCL点云库:ICP算法
ICP(Iterative Closest Point迭代最近点)算法是一种点集对点集配准方法。在VTK、PCL、MRPT、MeshLab等C++库或软件中都有实现,可以参见维基百科中的ICP Algorithm Implementations.
ICP算法采用最小二乘估计计算变换矩阵,原理简单且具有较好的精度,但是由于采用了迭代计算,导致算法计算速度较慢,而且采用ICP进行配准计算时,其对待配准点云的初始位置有一定要求,若所选初始位置不合理,则会导致算法陷入局部最优。PCL点云库已经实现了多种点云配准算法:
pcl::GeneralizedIterativeClosestPoint< PointSource, PointTarget > Class Template Reference
pcl::IterativeClosestPoint< PointSource, PointTarget, Scalar > Class Template Reference
pcl::IterativeClosestPointWithNormals< PointSource, PointTarget, Scalar > Class Template Reference
pcl::IterativeClosestPointNonLinear< PointSource, PointTarget, Scalar > Class Template Reference
pcl::JointIterativeClosestPoint< PointSource, PointTarget, Scalar > Class Template Reference
pcl::registration::IncrementalICP< PointT, Scalar > Class Template Reference
IterativeClosestPoint类提供了标准ICP算法的实现(The transformation is estimated based on SVD),算法迭代结束条件有如下几个:
- 最大迭代次数:Number of iterations has reached the maximum user imposed number of iterations (via setMaximumIterations)
- 两次变化矩阵之间的差值:The epsilon (difference) between the previous transformation and the current estimated transformation is smaller than an user imposed value (via setTransformationEpsilon)
- 均方误差(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算法的更多相关文章
- PCL点云库中的坐标系(CoordinateSystem)
博客转载自:https://blog.csdn.net/qq_33624918/article/details/80488590 引言 世上本没有坐标系,用的人多了,便定义了坐标系统用来定位.地理坐标 ...
- Windows下安装PCL点云库
原文链接:http://blog.csdn.net/u012337034/article/details/38270109 简介: 在Windows下安装PCL点云库的方法大概有两种: ...
- Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境
Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境 下载PCL For windows 软件包 到这个网站下载PCL-All-In-One Installer: ...
- PCL点云库(Point Cloud Library)简介
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=29 什么是PCL PCL(Point Cloud Library)是在吸收了 ...
- python利用pybind11调用PCL点云库
2019年7月9日14:31:13 完成了一个简单的小例子,python生成点云数据,利用pybind11传给PCL显示. ubuntu 16.04 + Anaconda3 python3.6 + ...
- PCL点云库:对点云进行变换(Using a matrix to transform a point cloud)
点云数据可以用ASCII码的形式存储在PCD文件中(关于该格式的描述可以参考链接:The PCD (Point Cloud Data) file format).为了生成三维点云数据,在excel中用 ...
- [PCL]1 PCL点云库安装
1.安装文件下载:官网,我还是比较喜欢别人编译好的安装包啊,哈哈. http://www.pointclouds.org/downloads/windows.html 2.傻瓜式安装(下面的依赖项都集 ...
- PCL点云库增加自定义数据类型
#include <pcl/filters/passthrough.h> #include <pcl/filters/impl/passthrough.hpp> // the ...
- 25 面向对象设计实例——基于PCL点云库的通用工具开发
0 引言 问题背景:pcl中提供了大量工具,用于对点云和三角面片文件进行处理和显示.在研究中,存在很多简易的需求,比如点云坐标转换,点云的打开显示以及同步显示,点云的最小包络求解,点云的格式转换等等. ...
随机推荐
- [OrangePi] Booting from USB drive
You can also boot from USB drive partition. The file named cmdline.txt must exist on BOOT (fat) part ...
- 一个容易被忽略的ReportingService超时问题
我们在使用Sql Server Reporting Service开发报表的时候,经常会遇到报表超时的问题,报表超时的原因有很多,也有很多地方可以设置报表的超时时间,比如在报表中的数据源(dataso ...
- spring Aop的一个demo
面向切面是什么我就不说了. 上代码: package com.foreveross.service.weixin.test; import java.lang.annotation.Documente ...
- javaWeb 使用 jsp 和 javaBean 实现计算器功能
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- android 下的技巧
1.删除屏幕的手势锁定 adb shell #登录 su $切换到su用户(手机需要root) cd /data/system #切换目录 rv gesture.key # 删除锁屏文件,然后进去的时 ...
- mmap直接控制底层【转】
转自:http://blog.csdn.net/xyyangkun/article/details/7830149 版权声明:本文为博主原创文章,未经博主允许不得转载. 这是在mini6410上测试成 ...
- java数组初始化
java数组初始化 //静态初始化数组:方法一 String cats[] = new String[] { "Tom","Sam","Mimi&qu ...
- HDU 5898:odd-even number(数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=5898 题意:给出一个区间[l, r],问其中数位中连续的奇数长度为偶数并且连续的偶数长度为奇数的个数.(1< ...
- 《Linux/Unix系统编程手册》
TCP的TIME_WAIT状态,超时时间为2倍MSL(IP报文超过TTL前最大生存时间,BSD规范为30s,RFC1122建议为2分钟).
- Cocos2dx框架常用单词(一)
收集了一些Cocos2dx里面主要单词的翻译. Toggle:切换Finite:有限Instant:瞬时interval:间隔Flip:翻转place:座位,放置Target:目标reverse:反向 ...