PCL学习笔记(3)——openni2_grabber从相机获取点云数据

源码

#include <pcl/io/openni2_grabber.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/pcl_macros.h>

//#ifdef _WIN32
//# define sleep(x) Sleep((x)*1000)
//#endif
// 这里需要注释掉,否则会报错

 class SimpleOpenNIViewer
 {
   public:
     SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}

     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
     {
       if (!viewer.wasStopped())
         viewer.showCloud (cloud);
     }

     void run ()
     {
       pcl::Grabber* interface = new pcl::io::OpenNI2Grabber();

       boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
         boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);

       interface->registerCallback (f);

       interface->start ();

       while (!viewer.wasStopped())
       {
         boost::this_thread::sleep(boost::posix_time::seconds (1));
       }

       interface->stop ();
     }

     pcl::visualization::CloudViewer viewer;
 };

 int main ()
 {
   SimpleOpenNIViewer v;
   v.run ();
   return 0;
 }
  • 创建了一个OpenNI2Grabber接口
pcl::Grabber* interface = new pcl::io::OpenNI2Grabber();
  • 用回调函数cloud_cb_地址创建boost::bind对象,给SimpleOpenNIViewer传递一个引用和参数_1作为占位符
   boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
         boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);

  • 将回调函数/方法注册到具有相应签名的信号
 interface->registerCallback (f);
  • 对于流式传输的设备,通过调用此方法启动流。基于触发器的设备,只需为每次启动调用触发设备一次。
interface->start ();
  • 判断窗口是否停止

参考 :点云视窗类CloudViewer(1)

while (!viewer.wasStopped())
 {
    boost::this_thread::sleep(boost::posix_time::seconds (1));
 }
  • 停止数据获取
interface->stop ();

参考:PCL中的OpenNI点云获取框架(OpenNI Grabber Framework in PCL)

拓展

另推荐一门深蓝学院开设讲解三维点云处理的线上课程,可以对整体框架的细节理解和运用都能起到很好的帮助:

链接:三维点云处理

技术交流可以去我主页左侧扫码进群

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Christo3

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值