本周主要任务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迭代交互的更多相关文章

  1. 《深度学习-改善深层神经网络》-第二周-优化算法-Andrew Ng

    目录 1. Mini-batch gradient descent 1.1 算法原理 1.2 进一步理解Mini-batch gradient descent 1.3 TensorFlow中的梯度下降 ...

  2. Surprise团队第二周项目总结

    Surprise团队第二周项目总结 项目进展 已实现五子棋人人模式部分 人人模式: 基本方式:采取黑棋先行,黑白交替的下棋顺序. 模式:通过鼠标点击相应棋盘中的"交叉点",在lay ...

  3. 《Machine Learning》系列学习笔记之第二周

    第二周 第一部分 Multivariate Linear Regression Multiple Features Note: [7:25 - θT is a 1 by (n+1) matrix an ...

  4. 2017-2018-1 Java演绎法 第二周 作业

    团队任务:讨论Android上的游戏软件 参考现代软件工程 第一章 [概论]练习与讨论: 软件有很多种,也有各种分类办法,本次团队任务是讨论选取Android上的一个游戏软件,考虑到每位组员接触的游戏 ...

  5. bug终结者 团队作业第二周

    bug终结者 团队作业第二周 我们小组选取游戏"开心消消乐",回答问题: 1. 此类软件是什么时候开始出现的, 这些软件是怎么说服你(陌生人)成为他们的用户的? 他们的目标都是盈利 ...

  6. 《团队作业第二周》五小福团队作业——UNO

    <团队作业第二周>五小福团队作业--UNO 一.修改完善上周提交的需求规格说明书 THE FIRST改变 首先:我们组的博客无小组分工及占比,这是第一个问题,当时我们在写博客的时候由于很多 ...

  7. 201771010126 王燕《面向对象程序设计(java)》第二周学习总结

    201771010126 王燕<面向对象程序设计(java)>第二周学习总结 一.理论知识学习部分 3.1j简单 的java应用程序 标识符由字母.下划线.美元符号和数字组成, 且第一个符 ...

  8. 2017-2018-2 1723《程序设计与数据结构》第九周作业 & 第二周结对编程 总结

    作业地址 第九次作业:https://edu.cnblogs.com/campus/besti/CS-IMIS-1723/homework/1878 (作业界面已评分,可随时查看,如果对自己的评分有意 ...

  9. 2018-2019-1 20189206 《Linux内核原理与分析》第二周作业

    Linux内核分析 第二周学习 知识总结 操作系统与内核 操作系统 指在整个系统中负责完成最基本功能和系统管理的那些部分 内核 实际是操作系统的内在核心 内核独立于普通应用程序,拥有受保护的内存空间和 ...

随机推荐

  1. Hibernate数据库持久层框架

    Hibernate是一种Java语言下的对象关系映射解决方案. 它是使用GNU宽通用公共许可证发行的自由.开源的软件.它为面向对象的领域模型到传统的关系型数据库的映射,提供了一个使用方便的框架.Hib ...

  2. 变量赋值(引用) php内核的实现(二)

    <?php $a=1; $b=&$a; $c=2; $a=&$c; echo $a."\n"; echo $b; 2 1 结论: 首先保存 左值的内存地址, ...

  3. Nginx SPDY缓冲区溢出漏洞

    漏洞版本: nginx 1.3.15 nginx 1.5.x 漏洞描述: CVE ID:CVE-2014-0133 Nginx是HTTP及反向代理服务器,同时也用作邮件代理服务器,由Igor Syso ...

  4. windows 远程桌面连接 RPi 2B

    /************************************************************************* * windows 远程桌面连接 RPi 2B * ...

  5. MenuInflater用法

    MenuInflater是用来加载menu布局文件的. 与LayoutInflater类似,应用程序运行时会预先加载资源中的布局文件,如果Menu布局中的资源比较多,会影响性能,所以可以选择MenuI ...

  6. android listview 使用checkbox问题

    在android中使用listview时需要了解listview加载数据的原理,为了避免listview由于列表项过多每次需要进行new造成性能低下的问题,android中的listview使用了控件 ...

  7. ubuntu下eclipse打开win下的代码中文出现乱码

    问题出现的原因:因为windows下默认的编码是GBK,在ubuntu下是UTF-8所以,所以在windows下的注释,在ubuntu下就变成了乱码. 解决的方案: 1)  eclipse->w ...

  8. linux防火墙启动、停止、查看

    停止防火墙 service iptables stop 启动防火墙 service iptables start 查看防火墙配置 iptables -L -n 修改的内容只是暂时保存在内存中,如果重启 ...

  9. Raspberry Pi无线路由器篇

    RaspberryPi可以折腾的方法很多,我将会吧自己的折腾经验与大家分享.   作为无线路由器,需要提供dhcp的功能和无线ap的能力,我们分别通过isc-dhcp-server和hostapd这两 ...

  10. ./wls1036_linux32.bin: /lib/ld-linux.so.2: bad ELF interpreter

    [CentOS]安装软件:/lib/ld-linux.so.2: bad ELF interpreter解决   环境: [orangle@localhost Downloads]$ uname -m ...