本周主要任务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. BZOJ_1031_[JSOI2007]_字符串加密_(后缀数组)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1031 长度为n的字符串形成环,枚举开头位置,得到n个长度为n的串,将这些串排序,然后按照顺序输 ...

  2. SGU 326 Perspective ★(网络流经典构图の竞赛问题)

    [题意]有n(<=20)只队伍比赛, 队伍i初始得分w[i], 剩余比赛场数r[i](包括与这n只队伍以外的队伍比赛), remain[i][j]表示队伍i与队伍j剩余比赛场数, 没有平局, 问 ...

  3. 【Java】Java运行cmd命令直接导出.sql文件

    Java中的Runtime.getRuntime().exec(commandStr)可以调用执行cmd命令 package Util; import java.io.File; import jav ...

  4. jQuery基础知识— 获得内容和属性

    jQuery拥有可操作HTML元素和属性的方法.   获得内容: text()--设置或返回所选元素的文本内容 html()--设置或返回所选元素的内容(包括HTML标记) val()--设置或返回表 ...

  5. 自定义SharePoint列表新增、编辑、查看页面(NewForm、EditForm、DispForm)

    转:http://blog.csdn.net/lance_lot1/article/details/7966571 在项目中,用户需求涉及在一个列表录入项目信息,选择一个项目后,与该项目相关的信息实现 ...

  6. EF Code First 学习笔记:约定配置

    要更改EF中的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面;还有一个就 ...

  7. HDU 5313 Bipartite Graph

    题意:给一个二分图,问想让二分图变成完全二分图最多能加多少条边. 解法:图染色+dp+bitset优化.设最终的完全二分图两部分点集为A和B,A中点个数为x,B中点个数为y,边数则为x × y,答案即 ...

  8. dll打包进需要发布的exe z

    http://www.cnblogs.com/Jarvin/p/3721195.html 我们需要发布的exe文件很多时候都可能会依赖于一堆松散的dll,如果想在发布 的时候只提供exe文件,而不想把 ...

  9. 【Jenkins】Linux搭建Jenkins平台

    为了配合上一篇的ant+jenkins做持续集成,需要在linux环境下搭建一个jenkins平台.网上有很多安装的例子,我主要记录一下自己遇到的问题,真真的是特别惆怅的,每次我遇到的问题都格外多. ...

  10. 第一章 Lambda表达式

    1.1 Why Lambdas? 当你操作多线程的时候,你会像下面这样将要处理的代码放到run()函数中: class Worker implements Runnable { public void ...