【C++】pcl中的简单点云可视化

  • 简单点云可视化
  • 结语

简单点云可视化

点云视窗类CloudViewer是简单显示点云的可视化工具,可以让用户用尽可能少的代码查看点云。点云视窗类不能应用于多线程应用程序中。

  1. 类CloudViewer定义在pcl/visualization/cloud_viewer.h文件中:
/** \brief Construct a cloud viewer, with a window name.* \param window_name This is displayed at the top of the window*/
CloudViewer (const std::string& window_name);
  • 带一个字符串类型的参数,是可视化窗口的名字
  1. 类CloudViewer的成员函数showCloud定义:
/** \brief Show a cloud, with an optional key for multiple clouds.* \param[in] cloud XYZ point cloud* \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.*/
void
showCloud (const MonochromeCloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
  • 第一个参数:一个XYZ类型的点云
  • 第二个参数:设置一个名字,相同名字的点云将覆盖之前的点云
  1. 使用回调函数时,被调用函数按如下方式声明:
/** Visualization callable function, may be used for running things on the UI thread.*/
using VizCallable = std::function<void (pcl::visualization::PCLVisualizer&)>;
  1. 类CloudViewer的成员函数runOnVisualizationThreadOnce定义:
/** \brief Run a callbable object on the UI thread. This will run once and be removed* @param x Use boost::ref(x) for a function object that you would like to not copy*/
void
runOnVisualizationThreadOnce (VizCallable x);
  • 在主函数中只执行一次回调函数
  1. 类CloudViewer的成员函数runOnVisualizationThread定义:
/** \brief Run a callbable object on the UI thread. Will persist until removed* @param x Use boost::ref(x) for a function object that you would like to not copy* \param key The key for the callable -- use the same key to overwrite.*/
void
runOnVisualizationThread (VizCallable x, const std::string& key = "callable");
  • 在主函数中持续执行回调函数
  1. 类CloudViewer的成员函数wasStopped定义:
/** \brief Check if the gui was quit, you should quit also* \param millis_to_wait This will request to "spin" for the number of milliseconds, before exiting.* \return true if the user signaled the gui to stop*/
bool
wasStopped (int millis_to_wait = 1);
  • 如果可视化窗口关闭,返回True
  1. 类PCLVisualizer定义在pcl/visualization/pcl_visualizer.h文件中:
/** \brief PCL Visualizer constructor.* \param[in] name the window name (empty by default)* \param[in] create_interactor if true (default), create an interactor, false otherwise*/
PCLVisualizer (const std::string &name = "", const bool create_interactor = true);
  1. 类PCLVisualizer的成员函数setBackgroundColor定义:
/** \brief Set the viewport's background color.* \param[in] r the red component of the RGB color* \param[in] g the green component of the RGB color* \param[in] b the blue component of the RGB color* \param[in] viewport the view port (default: all)*/
void
setBackgroundColor (const double &r, const double &g, const double &b, int viewport = 0);
  • 通过RGB三个通道设置视窗的背景颜色,范围归一化到(0到1)
  1. 类PCLVisualizer的成员函数addSphere定义:
/** \brief Add a sphere shape from a point and a radius* \param[in] center the center of the sphere* \param[in] radius the radius of the sphere* \param[in] id the sphere id/name (default: "sphere")* \param[in] viewport (optional) the id of the new viewport (default: 0)*/
template <typename PointT> bool
addSphere (const PointT &center, double radius, const std::string &id = "sphere",int viewport = 0);
  • 用点和半径添加一个球体
  • 第一个参数:球体的球心
  • 第二个参数:球体的半径
  • 第三个参数:球体的id/name
  • 第四个参数:视窗id,默认为0
  1. 类PCLVisualizer的成员函数removeShape定义:
/** \brief Removes an added shape from screen (line, polygon, etc.), based on a given ID* \note This methods also removes PolygonMesh objects and PointClouds, if they match the ID* \param[in] id the shape object id (i.e., given on \a addLine etc.)* \param[in] viewport view port from where the Point Cloud should be removed (default: all)*/
bool
removeShape (const std::string &id = "cloud", int viewport = 0);
  • 在指定视窗(参数二)中移走指定目标(参数一)
  1. 类PCLVisualizer的成员函数addText定义:
/** \brief Add a text to screen* \param[in] text the text to add* \param[in] xpos the X position on screen where the text should be added* \param[in] ypos the Y position on screen where the text should be added* \param[in] id the text object id (default: equal to the "text" parameter)* \param[in] viewport the view port (default: all)*/
bool
addText (const std::string &text,int xpos, int ypos,const std::string &id = "", int viewport = 0);
  • 在指定视窗(参数五)里添加文字(ID为参数四)

完整程序:

#include <pcl/visualization/cloud_viewer.h> //点云视窗类:CloudViewer头文件声明
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>int user_data;void
viewerOneOff (pcl::visualization::PCLVisualizer& viewer) // 设置回调函数viewerOneOff
{viewer.setBackgroundColor (0.0, 1.0, 0.0); // 设置背景颜色pcl::PointXYZ o; o.x = 1.0; o.y = 0;o.z = 0;viewer.addSphere (o, 0.25, "sphere", 0); // 添加一个球体std::cout << "i only run once" << std::endl;}void
viewerPsycho (pcl::visualization::PCLVisualizer& viewer) // 设置回调函数viewerPsycho
{static unsigned count = 0;std::stringstream ss;ss << "Once per viewer loop: " << count++;viewer.removeShape ("text", 0); // 移走旧文字viewer.addText (ss.str(), 200, 300, "text", 0); // 添加新文字user_data++;
}int
main ()
{pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); // 创建一个PointCloud<PointXYZ> boost共享指针,并进行实例化为cloudpcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud); // 读取点云文件pcl::visualization::CloudViewer viewer("Cloud Viewer"); // 创建一个可视化窗口viewer.showCloud(cloud); // 在窗口中显示点云viewer.runOnVisualizationThreadOnce (viewerOneOff); // 调用一次viewerOnOffviewer.runOnVisualizationThread (viewerPsycho); // 持续调用viewerPsychowhile (!viewer.wasStopped ()){user_data++;}return 0;
}

程序执行结果:

结语

如果您有修改意见或问题,欢迎留言或者通过邮箱和我联系。
手打很辛苦,如果我的文章对您有帮助,转载请注明出处。

【C++】pcl中的简单点云可视化相关推荐

  1. PCL中的OpenNI点云获取框架(OpenNI Grabber Framework in PCL)

    从PCL 1.0开始,PCL(三维点云处理库Point Cloud Library)提供了一个通用采集接口,这样可以方便地连接到不同的设备及其驱动.文件格式和其他数据源.PCL集成的第一个数据获取驱动 ...

  2. creator qt 设置换行方式_win下使用QT添加VTK插件实现点云可视化GUI

    大家在做点云的时候经常会用到QT,但是我们需要使用QT做点云的可视化的时候又需要VTK,虽然我们在windows下安装PCL的时候就已经安装了VTK,由于跟着PCL安装的VTK是没有和QT联合编译的, ...

  3. win下使用QT添加VTK插件实现点云可视化GUI

    摘要​ 大家在做点云的时候经常会用到QT,但是我们需要使用QT做点云的可视化的时候又需要VTK,虽然我们在windows下安装PCL的时候就已经安装了VTK,由于跟着PCL安装的VTK是没有和QT联合 ...

  4. 斯坦福的著名小兔子模型的点云数据_传统方法的点云分割以及PCL中分割模块

    之前在微信公众号中更新了以下几个章节 1,如何学习PCL以及一些基础的知识 2,PCL中IO口以及common模块的介绍 3,  PCL中常用的两种数据结构KDtree以及Octree树的介绍 有兴趣 ...

  5. PCL之点云可视化--CloudViewer

    点云视窗类CloudViewer是简单的可视化点云工具类,仅用几行代码就可以让用户查看点云:但需要注意的是该类不能用于多线程应用程序中. 代码展示 #include<pcl/point_type ...

  6. python点云可视化工具_救命!点云可视化(不需配置PCL)

    分享一波简单的可视化bin格式点云的方法. 先大概讲下背景,目前激光雷达采集的点云文件大多基于ROS,然后转化为pcd.bin格式进行处理.(ros-pcd-bin格式之间相互转换格式有相应的工具,如 ...

  7. PCL中3D点云特征描述与提取(三)

    PCL中3D点云特征描述与提取(三) 1 如何从一个深度图像中提取NARF特征 2 RoPs特征 2.1 理论基础 2.1.1 生物视觉认知学启示 2.1.2 局部参考坐标框架构建 2.1.3 RoP ...

  8. 传统方法的点云分割以及PCL中分割模块

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 摘要 三维点云分割是将同属性的点云物体分割出来,以便于单独对该点云 ...

  9. PCL中点云可视化:坐标字段、随机、单一颜色、法向量

    PCL中viewer添加并显示的点云过于简单,现总结常见的几种点云渲染方式,便于点云结果的显示. (1)按照点云坐标x.y.z坐标值中字段给点云进行赋值渲染 #include <pcl/poin ...

  10. 传统的点云分割方法及PCL中的分割模块

    参考:https://www.cnblogs.com/li-yao7758258/p/10908980.html 三维点云分割是将同属性的点云物体分割出来,以便于单独对该点云物体处理,但是由于点云数据 ...

最新文章

  1. 安卓性能测试之 adb shell 常用命令
  2. oracle中类似indexof用法_instr函数
  3. linux 使用FIO测试磁盘iops
  4. 牛客题霸 NC21 链表内指定区间反转
  5. VTK:Cell Edge Neighbors用法实战
  6. 支付宝 PEM routines:PEM_read_bio:no start line
  7. mysql mos login_MySQL 中常用的函数
  8. 社会计算:服务群体社会的大数据科学
  9. 1043 幸运号码 数位DP
  10. [转载]i++是否是线程安全的?
  11. Python游戏篇:细节之大型游戏爆炸效果(附代码)
  12. 清华大学保研计算机推荐信模板,清华保研推荐信模板
  13. Hbuilder里运行到手机或模拟器手机和电脑配置
  14. select标签 selected 选中状态动态查询
  15. [笔记分享] [RPM] RPM T32 dump方法
  16. 翻译app上的图片文字信息提取好神奇?如何实现一个文字图片识别程序
  17. SSL证书中pem der cer crt csr pfx的区别
  18. linux centos 7安装极点五笔输入法
  19. 前端-html-01
  20. PDF怎么转换成PPT?分享给你两个小妙招

热门文章

  1. deeptools | bam to BigWig, 并使用IGV可视化峰图差异
  2. GPL授权GPL到底是什么?为什么MySQL可以收费?
  3. Flash MX 2004的Alpha Fader
  4. 通过ktr文件写交换代码
  5. 托管c++ (CLI) String^ 、 std::string 、 std::ostringstream的相互转化
  6. LOJ#6198. 谢特【后缀自动机/数组 + Trie树查异或最大值 + Trie树合并】
  7. Selenium元素定位神器工具谷歌浏览器插件-ChroPath介绍,安装与使用
  8. 计算机专业考研的好学校排名2015,计算机类专业考研最好的学校排名
  9. 一般常见电子邮箱都有哪几种?最常用的邮箱有哪些?
  10. 关于Gateway实现JWT登陆拦截过滤器