PCL练习(一)——从OpenNI相机抓取点云

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/uniqueyyc/article/details/82714479

http://pointclouds.org/documentation/tutorials/openni_grabber.php#openni-grabber

在Ubuntu 16.04上利用kdevelop的程序示例:

CmakeLists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
# rgb_depth_saver为工程的名字
project(rgb_depth_saver)
# PCL
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
# 运行主程序
add_executable(rgb_depth_saver main.cpp)
# 链接库
target_link_libraries(rgb_depth_saver ${PCL_LIBRARIES})

main.cpp

 #include <pcl/io/openni_grabber.h> 
 #include <pcl/visualization/cloud_viewer.h> 

 class SimpleOpenNIViewer
 {
   public:
     SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}//定义一个显示界面
     //定义回调函数cloud_cb_,获取到数据时对数据进行处理
     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
     {
       if (!viewer.wasStopped())
       //有输入时就显示
         viewer.showCloud (cloud);
     }

     void run ()
     {
       //为openni的设备创建一个新的grabber
       pcl::Grabber* interface = new pcl::OpenNIGrabber();
       //使得回调函数来自于成员函数
       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;
 }

效果
这里写图片描述

猜你喜欢

转载自blog.csdn.net/uniqueyyc/article/details/82714479