第二周: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内核分析 第二周学习 知识总结 操作系统与内核 操作系统 指在整个系统中负责完成最基本功能和系统管理的那些部分 内核 实际是操作系统的内在核心 内核独立于普通应用程序,拥有受保护的内存空间和 ...
随机推荐
- java中synchronized的用法详解
记下来,很重要. Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码. 一.当两个并发线程访问同一个对象object中的这个synchron ...
- ♫【jQuery插件】图片放大镜
JQZoom
- 使用SVN小结
自从加入团队后,开始使用SVN,以下是个人对SVN的一些认识和小结. 一.SVN是什么? SVN是版本管理工具,譬如团队进行项目开发,项目代码都储存在服务器上,成员可用SVN在本地获得并更新代码. 二 ...
- List<HashMap>和HashMap
例如select查询出的是学号.姓名,比如查出符合条件的是学号是0810的小红,学号是0811的小明,组织起来如下: list.add(hashmap1);list.add(hashmap2); ...
- MyEclipse2014安装ADT插件(适用于其他版本)
这次,本文采用公认的最佳插件安装方式——link方式来安装ADT插件,此方法适用于Eclipse以及MyEclipse其他版本.下面为大家一一道来: 大致过程如下: 官方的在线安装很麻烦,找了很久,终 ...
- 转载crontab例行工作调度
转自:http://blog.sina.com.cn/s/blog_95ee143401017y70.html crontab [-e [UserName]|-l [UserName]|-r [Use ...
- Clear All of Them I(HDU 3920状压dp)
题意:给有2*n个敌人的位置,枪在(0,0)位置,一次能消灭两个敌人,耗费能量为枪到一个敌人,由这个敌人再到另个敌人的的距离和,求消灭所有敌人最小耗费能量. 分析:一次枚举状态的两位即可 #inclu ...
- e2e 自动化集成测试 架构 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step (一) 京东 商品搜索
之前有发布一篇文章“e2e 自动化集成测试 环境搭建 Node.js Selenium WebDriverIO Mocha Node-Inspector”, 主要是讲了,如何搭建环境, 其中开发环境使 ...
- 决策树学习(ID3)
参考:<机器学习实战> 优点:计算复杂度不高, 输出结果易于理解,对中间值的缺失不敏感,可以处理不相关特 征数据. 缺点:可能会产生过度匹配问题. 适用数据类型:数值型和标称型. 创建分支 ...
- HDU 1029 Ignatius and the Princess IV DP
kuangbin 专题 这题,有很多种解法. 第一种: 直接比较每个数出现次数. #include<iostream> #include<string> #include< ...