您的位置:首页 > 其它

PCL+Xtion 采集并显示点云图像

2014-07-28 14:57 253 查看
平台:PCL1.7.1 vs2010

硬件:华硕Xtion

显示采集的点云数据并保存为pcd格式:



代码如下:

#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/pcd_io.h>
#include <iostream>
#include <string>
#include <strstream>
#include <pcl/common/time.h>
#include <pcl/console/parse.h>

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

void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &cloud)
{

if (!viewer.wasStopped())
{
viewer.showCloud (cloud);
std::stringstream ss;
ss << std::setprecision (12) << pcl::getTime () * 100 << ".pcd";
pcl::PCDWriter w;
w.writeBinaryCompressed (ss.str (), *cloud);
}
}

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

boost::function<void (const pcl::PointCloud<pcl::PointXYZRGB>::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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: