近期需要将三维点云图实时显示出来,关于点云库,有PCL和opengl。pcl在处理点云的算法上有优势,opengl做点云的显示与渲染有优势。

由于点云处理操作较多,所以就选择了PCL的库来处理。

PCL中点云的显示主要有两个类:1. pcl::visualization::CloudViewer; 2. pcl::visualization::PCLVisualizer。

前面一个类主要做简单的点云显示,后面一个有更加丰富的设置接口。下面简单的介绍两种

  1. pcl::visualization::CloudViewer(这里偷懒直接把官方的示例拖过来,网址:http://www.pointclouds.org/documentation/tutorials/cloud_viewer.php#cloud-viewer)
  • 下面是最简单的显示,其中PointXYZRGB可以替换为PointXYZ, PointXYZRGBA等多种点云的格式。

#include <pcl/visualization/cloud_viewer.h>
//...
void
foo ()
{
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
  //... populate cloud
  pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
  viewer.showCloud (cloud);
  while (!viewer.wasStopped ())
  {
  }

}

  • 如果想要在一个单独的线程中跑,可以看下面这个例子

#include <pcl/visualization/cloud_viewer.h>#include <iostream>#include <pcl/io/io.h>#include <pcl/io/pcd_io.h>
   
int user_data;
   
void
viewerOneOff (pcl::visualization::PCLVisualizer& viewer){
    viewer.setBackgroundColor (1.0, 0.5, 1.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){
    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);
   
    //FIXME: possible race condition here:
    user_data++;}
   
int
main (){
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud);
   
    pcl::visualization::CloudViewer viewer("Cloud Viewer");
   
    //blocks until the cloud is actually rendered
    viewer.showCloud(cloud);
   
    //use the following functions to get access to the underlying more advanced/powerful
    //PCLVisualizer
   
    //This will only get called once
    viewer.runOnVisualizationThreadOnce (viewerOneOff);
   
    //This will get called once per visualization iteration
    viewer.runOnVisualizationThread (viewerPsycho);
    while (!viewer.wasStopped ())
    {
    //you can also do cool processing here
    //FIXME: Note that this is running in a separate thread from viewerPsycho
    //and you should guard against race conditions yourself...
    user_data++;
    }

return 0;}

  1. 如果想要更加丰富的点云显示,如给点云添加颜色、显示点云中的法矢、在窗口中自己画图案、自定义视角的位置,可以采用pcl::visualization::PCLVisualizer。

在官方网页 :http://www.pointclouds.org/documentation/tutorials/pcl_visualizer.php#pcl-visualizer  有详细的点云显示示例代码,这里不再粘贴。

下面贴出一个基于pcl::visualization::PCLVisualizer 实时显示点云流的代码。

#include <pcl/point_types.h>

#include <pcl/visualization/cloud_viewer.h>

boost::mutex updateModelMutex;

boost::shared_ptr<pcl::visualization::PCLVisualizer> simpleVis (pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud)

{

// --------------------------------------------

// -----Open 3D viewer and add point cloud-----

// --------------------------------------------

boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));

viewer->setCameraPosition(0, 0, 0, 0, 0, 0, 0, 0, -1);

viewer->setBackgroundColor(0,0,0);

viewer->addPointCloud<pcl::PointXYZ> (cloud, "sample cloud");

viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");

viewer->initCameraParameters ();

return (viewer);

}

void viewerRunner(boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer)

{

while (!viewer->wasStopped ())

{

viewer->spinOnce (100);

boost::this_thread::sleep (boost::posix_time::microseconds (100));

}

}

void main()

{

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr (new pcl::PointCloud<pcl::PointXYZ>);

pcl::PointCloud<pcl::PointXYZ> &pcloud1 = *cloud_ptr;

boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));

pcloud1.points.push_back( pcl::PointXYZ(10, 10, 80) );

pcloud1.width = cloud_ptr->size();

pcloud1.height = 1;

pcloud1.is_dense = true;

viewer = simpleVis(cloud_ptr);

boost::thread vthread(&viewerRunner,viewer);

while(1)//循环抓取深度数据

{

pcloud1.clear();

for ( int _row = 0; _row < disp.rows; _row++ )

{

for ( int _col = 0; _col < disp.cols; _col++ )

{

float x, y, z;

pcl::PointXYZ ptemp(x, y, z);

pcloud1.points.push_back( ptemp );

}

}

pcloud1.width = cloud_ptr->size();

pcloud1.height = 1;

pcloud1.is_dense = true;

boost::mutex::scoped_lock updateLock(updateModelMutex);

viewer->updatePointCloud<pcl::PointXYZ>(cloud_ptr,"sample cloud");

updateLock.unlock();

boost::this_thread::sleep (boost::posix_time::microseconds (100));

}

vthread.joint();

}

--------------------- 本文来自 YvanY 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/u014049811/article/details/75012743?utm_source=copy

PCL库实时显示点云流相关推荐

  1. PCL库VTK显示点云法向时出错:no override found for vtkActor

    错误:no override found for vtkActor (我的环境是pcl1.8.1)解决办法: 1. 头文件中添加 #include <vtkAutoInit.h> VTK_ ...

  2. Qt/C++编写监控实时显示和取流回放工具(回放支持切换进度)

    一.前言 现在各个监控大厂做的设备,基本上都会支持通过rtsp直接取流显示,而且做的比较好的还支持通过rtsp回放取流,基本上都会约定一个字符串的规则,每个厂家都是不一样的规则,比如回放对应的rtsp ...

  3. ORB-SLAM2实时显示稠密点云图

    文章目录 先上代码 生成过程 系统入口 跟踪线程 遇到问题 程序运行段错误,异常终止 定义了Eigen类型成员的字节对齐问题 其它 ROS在线生成稠密点云 代码 运行 进一步工作 动态SLAM相关 语 ...

  4. 利用PCL库从点云数据生成深度图像及关键点提取

    利用PCL库从点云数据生成生成深度图像及关键点提取 利用PCL库从点云数据生成深度图像及关键点提取 本想利用标准点云数据库分割成若干块,利用标准点云数据生成深度图像作为数据库用来验证算法,目前效果不是 ...

  5. PCL Show Point Cloud 显示点云

    在使用PCL库的时候,经常需要显示点云,可以用下面这段代码: #include <pcl/visualization/cloud_viewer.h>pcl::PointCloud<p ...

  6. python中texttable库显示实时数据_用Python串口实时显示数据并绘图pyqtgraph

    用Python串口实时显示数据并绘图 使用pyserial进行串口传输 一.安装pyserial以及基本用法 在cmd下输入命令pip install pyserial 注:升级pip后会出现 &qu ...

  7. 基于PCL库的通过ICP匹配多幅点云方法

    基于PCL库的通过ICP匹配多幅点云方法 前言 Code Result 前言 PCL库中有很多配准的方式,主要都是基于ICP ICP算法最初由Besl和Mckey提出,是一种基于轮廓特征的点配准方法. ...

  8. PCL:PCL可视化显示点云

    (1):引用:仅仅是简单的显示点云,可以使用CloudViewer类.这个类非常简单易用.但要注意,它不是线程安全的.如果要用于多线程,还要参考PCLVisualizer. 需要注意的是,PointC ...

  9. 双11特刊|购物车实时显示到手价,看云原生内存数据库Tair如何提升用户体验?

    阿里云自研内存数据库Tair诞生于2009年,是一种支持高并发低延迟访问的云原生内存数据库,完全兼容Redis,已历经多年双11大促考验,提供核心在线访问加速能力,显著提升系统吞吐量. 作为双11大促 ...

  10. 3d激光雷达开发(从halcon看点云pcl库)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 做点云开发的,很少有不知道pcl库的,这一点就有点像做数字图像处理的,很少有不知道opencv的 ...

最新文章

  1. Linux 中Sublime Text 3无法输入中文的问题
  2. 杭电ACM刷题(1):1002,A + B Problem II
  3. mysql触发器对同一张表做操作_MySql 触发器对同表操作
  4. WebView::drawExtras
  5. Asp.net core与golang web简单对比测试
  6. django连接mysql步骤_使用Django连接Mysql数据库步骤
  7. 20155330 2016-2017-2 《Java程序设计》第五周学习总结
  8. [html] svg如何转为字体图标?
  9. [资源]基于 Pytorch 的 TorchGAN开源了!
  10. VM虚拟机上的CentOS 7系统重置root用户密码
  11. WORD各个章节批量另起一页?
  12. 终端启动tomcat报错 command not found 解决方法 (含启动和关闭命令)
  13. cdev 结构体、设备号相关知识解析
  14. python中注释的定义_Python注释及变量
  15. 算法之二叉树各种遍历
  16. 微信小程序---详情页
  17. 在网易咔哒上面制作SCRATCH小程序
  18. 2023年,莫荒废了时光。
  19. CSS3视窗单位vw、vh、vmin、vmax说明
  20. Firefox火狐无法启动出现弹窗--小黑日常超细解决教程

热门文章

  1. 4-7-4 校验ISBN-10编码 (10 分)
  2. U盘不能分区,不能格式化,解决方案
  3. 植树问题java,云南省优秀多媒体育软件大赛公示.doc
  4. ipad html 自定义裁剪图片大小,如何在iPhone或iPad上裁剪和编辑照片 | MOS86
  5. 第十一周博客作业西北师范大学|李晓婷
  6. java随机生成迷宫游戏地图_java随机生成迷宫(图的深度优先遍历)
  7. 【历史上的今天】3 月 2 日:雅虎正式成立;PC 设计先驱诞生;Excite@Home 破产
  8. 立体栅格地图_基于滑动窗口的室内三维立体栅格地图特征点提取方法与流程
  9. IFrame里面的子页面html内容变化时,怎么动态改变IFrame的高度
  10. 外贸找客户软件工具-G-EXTRACTOR-谷歌商家