本周主要任务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. 谈谈Runtime类中的freeMemory,totalMemory,maxMemory等几个方法

    最近在网上看到一些人讨论到java.lang.Runtime类中的freeMemory(),totalMemory(),maxMemory ()这几个方法的一些问题,很多人感到很疑惑,为什么,在jav ...

  2. poj 2195 Going Home(最小费用最大流)

    题目:http://poj.org/problem?id=2195 有若干个人和若干个房子在一个给定网格中,每人走一个都要一定花费,每个房子只能容纳一人,现要求让所有人进入房子,且总花费最小. 构造一 ...

  3. UVa 1151 (枚举 + MST) Buy or Build

    题意: 平面上有n个点,现在要把它们全部连通起来.现在有q个套餐,如果购买了第i个套餐,则这个套餐中的点全部连通起来.也可以自己单独地建一条边,费用为两点欧几里得距离的平方.求使所有点连通的最小费用. ...

  4. bzoj1433:[ZJOI2009]假期的宿舍

    明显的二分图最大匹配. #include<cstdio> #include<cstring> #include<cctype> #include<algori ...

  5. LeetCode Implement Trie (Prefix Tree) (实现trie树3个函数:插入,查找,前缀)

    题意:实现trie树的3个功能,只含小写字母的串. 思路:老实做即可! class TrieNode { public: TrieNode* chd[]; bool flag; // Initiali ...

  6. 【Mac】『终端』显示、隐藏所有文件

    如果你想打开整个系统的隐藏文件可以在终端下输入以下命令 defaults write com.apple.finder AppleShowAllFiles -bool true 关闭显示隐藏功能def ...

  7. 学习Erlang--1、入门

    1.正式起航 从前,一名程序员偶然读到了一本古怪的语言图书,相等其实不是相等,变量其实是不能改变的,语法是那么陌生,它甚至不是面向对象,这些程序实在是太过另类…… 另类的不仅仅是程序,编程的教学步骤也 ...

  8. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.10

    Every $k\times k$ positive matrix $A=(a_{ij})$ can be realised as a Gram matrix, i.e., vectors $x_j$ ...

  9. 在文件中读取、存储Json格式的字符串

    public class Weather { static readonly string FilePath = System.Environment.CurrentDirectory + @&quo ...

  10. 《Python基础教程(第二版)》学习笔记 -> 第六章 抽象

    抽象和结构 本章将会介绍如何让将语句组织成函数,还会详细介绍参数(parameter)和作用域(scope)的概念,以及递归的概念及其在程序中的用途. 创建函数 函数可以调用,它执行某种行为,并返回某 ...