第二周:01 ICP迭代交互
本周主要任务01:利用PCL库函数,ICP融合两个角度的点云
任务时间:2014年9月8日-2014年9月14日
任务完成情况:可以使用键盘交互,显示每次ICP迭代结果
任务涉及基本方法:
1.PCL库中ICP相关函数,ICP交互迭代 参考官方教程 http://pointclouds.org/documentation/tutorials/interactive_icp.php#interactive-icp
程序文件:
1.icpInteractive.cpp
//icpInteractive.cpp
//函数:main()
//功能:导入两个视角的点云数据,第一个点云数据作为源,第二个点云数据作为目标,进行icp配准,
// 并显示配准结果,按空格进行每次迭代的交互
//输入:导入文件名,输出文件名 例:可执行文件根目录下,命令行输入 xml2pcd file1.pcd file2.pcd
//创建时间:2014/09/10
//最近更新时间:2014/09/17
//创建者:肖泽东 #include <iostream> #include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/registration/icp.h> bool next_iteration = false; //显示帮助
void showHelp(char* program_name)
{
std::cout << std::endl;
std::cout << "Usage: " << program_name << " sourcefile.pcd targetfile.pcd" << std::endl;
std::cout << "-h: Show this help." << std::endl;
} //键盘交互
void keyboardEventOccurred (const pcl::visualization::KeyboardEvent& event,
void* nothing)
{
if (event.getKeySym () == "space" && event.keyDown ()) //判别是否按下空格按键
next_iteration = true; //允许下一次迭代
} int main(int argc, char** argv)
{
// 显示帮助文档
if(pcl::console::find_switch (argc,argv,"-h") || pcl::console::find_switch(argc,argv,"--help"))
{
showHelp(argv[]);
return ;
} std::vector<int> filenames; //输入参数 文件名向量 filenames = pcl::console::parse_file_extension_argument(argc, argv, ".pcd"); //查找输入中的pcd文件
if (filenames.size() != ) //限定输入两个pcd点云文件
{
std::cout << "input pcd file format wrong" << std::endl; //不是两个,显示出错
showHelp(argv[]);
return -;
}
//定义配准源点云和目标点云
pcl::PointCloud<pcl::PointXYZ>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZ> ()); //源点云
pcl::PointCloud<pcl::PointXYZ>::Ptr target_cloud (new pcl::PointCloud<pcl::PointXYZ> ()); //目标点云
pcl::PointCloud<pcl::PointXYZ>::Ptr aligned_cloud(new pcl::PointCloud<pcl::PointXYZ> ());; //配准后点云 if(pcl::io::loadPCDFile(argv[filenames[]],*source_cloud) < ) //导入源点云
{
std::cout << "Error loading point cloud " << argv[filenames[]] << std::endl;
showHelp(argv[]);
return -;
}
if(pcl::io::loadPCDFile(argv[filenames[]],*target_cloud) < ) //导入目标点云
{
std::cout << "Error loading point cloud " << argv[filenames[]] << std::endl;
showHelp(argv[]);
return -;
} //ICP 配准定义
pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp; //定义ICP类型实例icp
*aligned_cloud = *source_cloud; //初始化配准点云为源点云
icp.setInputCloud(aligned_cloud); //初始化源点云
icp.setInputTarget(target_cloud); //初始化目标点云
//设置ICP基本参数
icp.setMaxCorrespondenceDistance(); //设置对应点容忍最大距离
icp.setMaximumIterations(); //设置每次按键触发最大迭代次数
icp.setRANSACIterations(); //不进行RANSAC迭代 // Visualization显示结果
printf( "\nPoint cloud colors : white = original point cloud\n"
" red = transformed point cloud\n"); pcl::visualization::PCLVisualizer viewer ("ICP test example"); //定义显示窗口
int v1 (); //分隔窗口v1
int v2 (); //分隔窗口v2
viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v1); //...viewPort(x_min,y_min,x_max,y_max,int ..)
viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v2); //
//std::cout << "v1=" << v1 << "v2=" << v2<< std::endl; // Define R,G,B colors for the point cloud
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> source_cloud_color_handler (source_cloud, , , );//White
// We add the point cloud to the viewer and pass the color handler
viewer.addPointCloud (source_cloud, source_cloud_color_handler, "source_cloud_v1", v1); pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> target_cloud_color_handler (target_cloud, , , ); // Red
viewer.addPointCloud (target_cloud, target_cloud_color_handler, "target_cloud_v1", v1); //viewer.addCoordinateSystem (1.0, "cloud", 0);
//viewer.setBackgroundColor(0.05, 0.05, 0.05, 0); // Setting background to a dark grey
viewer.setBackgroundColor(0.05, 0.05, 0.05, v1);
viewer.setBackgroundColor(0.05, 0.05, 0.05, v2);
viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, , "source_cloud_v1");
viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, , "target_cloud_v1");
//viewer.setPosition(800, 400); // Setting visualiser window position // Define R,G,B colors for the point cloud
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> aligned_cloud_color_handler (aligned_cloud, , , ); //White
// We add the point cloud to the viewer and pass the color handler
viewer.addPointCloud (aligned_cloud, aligned_cloud_color_handler, "aligned_cloud_v2", v2);
viewer.addPointCloud (target_cloud, target_cloud_color_handler, "target_cloud_v2", v2); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, , "aligned_cloud_v2");
viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, , "target_cloud_v2");
//viewer.setPosition(800, 400); // Setting visualiser window position
// Register keyboard callback :
viewer.registerKeyboardCallback (&keyboardEventOccurred, (void*) NULL); //对齐响应键盘事件 int iterations = ; //迭代次数
while (!viewer.wasStopped ())
{ // Display the visualiser until 'q' key is pressed
viewer.spinOnce (); //运行视图
if(next_iteration)
{
icp.align(*aligned_cloud); //ICP配准对齐结果
std::cout << "has converged:" << icp.hasConverged() << " score: " <<
icp.getFitnessScore() << std::endl; //配准分析...icp.hasConverge()=1,表示收敛
std::cout << icp.getFinalTransformation() << std::endl; //获取变换矩阵
std::cout << "Iteration = " << ++iterations; //迭代次数加1
if(iterations ==) //迭代满100次停止迭代
return ;
viewer.updatePointCloud (aligned_cloud, aligned_cloud_color_handler, "aligned_cloud_v2"); //更新点云
}
next_iteration = false; //本次迭代结束,不直接进行下一次迭代,等待下次迭代触发
}
return ;
}
2.CMakeLists.txt
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(pcl_icpInteractive)
find_package(PCL 1.6 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (icpInteractive icpInteractive.cpp)
target_link_libraries (icpInteractive ${PCL_LIBRARIES})
第二周:01 ICP迭代交互的更多相关文章
- 《深度学习-改善深层神经网络》-第二周-优化算法-Andrew Ng
目录 1. Mini-batch gradient descent 1.1 算法原理 1.2 进一步理解Mini-batch gradient descent 1.3 TensorFlow中的梯度下降 ...
- Surprise团队第二周项目总结
Surprise团队第二周项目总结 项目进展 已实现五子棋人人模式部分 人人模式: 基本方式:采取黑棋先行,黑白交替的下棋顺序. 模式:通过鼠标点击相应棋盘中的"交叉点",在lay ...
- 《Machine Learning》系列学习笔记之第二周
第二周 第一部分 Multivariate Linear Regression Multiple Features Note: [7:25 - θT is a 1 by (n+1) matrix an ...
- 2017-2018-1 Java演绎法 第二周 作业
团队任务:讨论Android上的游戏软件 参考现代软件工程 第一章 [概论]练习与讨论: 软件有很多种,也有各种分类办法,本次团队任务是讨论选取Android上的一个游戏软件,考虑到每位组员接触的游戏 ...
- bug终结者 团队作业第二周
bug终结者 团队作业第二周 我们小组选取游戏"开心消消乐",回答问题: 1. 此类软件是什么时候开始出现的, 这些软件是怎么说服你(陌生人)成为他们的用户的? 他们的目标都是盈利 ...
- 《团队作业第二周》五小福团队作业——UNO
<团队作业第二周>五小福团队作业--UNO 一.修改完善上周提交的需求规格说明书 THE FIRST改变 首先:我们组的博客无小组分工及占比,这是第一个问题,当时我们在写博客的时候由于很多 ...
- 201771010126 王燕《面向对象程序设计(java)》第二周学习总结
201771010126 王燕<面向对象程序设计(java)>第二周学习总结 一.理论知识学习部分 3.1j简单 的java应用程序 标识符由字母.下划线.美元符号和数字组成, 且第一个符 ...
- 2017-2018-2 1723《程序设计与数据结构》第九周作业 & 第二周结对编程 总结
作业地址 第九次作业:https://edu.cnblogs.com/campus/besti/CS-IMIS-1723/homework/1878 (作业界面已评分,可随时查看,如果对自己的评分有意 ...
- 2018-2019-1 20189206 《Linux内核原理与分析》第二周作业
Linux内核分析 第二周学习 知识总结 操作系统与内核 操作系统 指在整个系统中负责完成最基本功能和系统管理的那些部分 内核 实际是操作系统的内在核心 内核独立于普通应用程序,拥有受保护的内存空间和 ...
随机推荐
- poj1286Necklace of Beads(ploya定理)
链接 这个东东是新知识 let's 从头学起吧 这篇文库讲的不错 至少把各种概念学了一遍 然后再看此题 共有两种类型的置换 一种是旋转之后相同算一种 一种是翻转之后相同算一种 对于旋转 共有N次置换 ...
- NOI2006最大获利
终于搞明白了…… x到y有边意味着选x必须选y,所以才会有闭合子图中一个点的后继一定也在这个闭合子图中. 接下来按照s连正权,负权连t就ok了 type node=record go,next,c:l ...
- 自定义Sharepoint的登陆页面
转:http://www.cnblogs.com/jecoso/archive/2008/05/25/1207151.html 原文作者:Damon Armstrong 原文地址:http://www ...
- 通过autofac教你彻底明白依赖解耦(二)理论结合实践 - 大侠.Net
上节说了一下基本的理论知识,例子可能不太好,不过无所谓了,目的是要让大家明白啥是依赖倒置和依赖注入,目的就达到了,简单一句话,这2玩意都是用来解耦合的. 不过依赖倒置这个词哥哥真不敢苟同,哥哥来个颠覆 ...
- MySQL查询大小写是否敏感问题分析
mysql数据库在做查询时候,有时候是英文字母大小写敏感的,有时候又不是的,主要是由mysql的字符校验规则的设置决定的,通常默认是不支持的大小写字母敏感的. 1. 什么是字符集和校验规则? 字符集 ...
- linux防火墙启动、停止、查看
停止防火墙 service iptables stop 启动防火墙 service iptables start 查看防火墙配置 iptables -L -n 修改的内容只是暂时保存在内存中,如果重启 ...
- Java序列化 如何把多个对象存储在一个文件中
/** * 用于保存模板文件,内容包括: * 1,标志位,1 int * 2,版本 1 int * 3,数据头长度 1 int * 4,预留数据头空间 5120 byte * 5,后续数据长度 ...
- Web网站常规测试方法
功能测试 1. 安装测试: 安装过程中对于缺省安装目录及任意指定的安装目录,是否都能正确安装: 若是选择安装,查看能否实现其相应的功能: 在所有能中途退出安装的位置退出安装程序后,验证此程序并未安装成 ...
- 【转】java list用法示例详解
转自:http://www.jb51.net/article/45660.htm java中可变数组的原理就是不断的创建新的数组,将原数组加到新的数组中,下文对java list用法做了详解. Lis ...
- 同样的JS写法,为啥只有IE9模式正常?
使用 IE F12 开发者工具,选择不同的“文档模式” 从IE7 - IE9,只有IE9正常! <!DOCTYPE html> <html> <script type=& ...