Kinect+PCL读取点云并存储

        捣腾很久终于成功了,这是为之后完成实时跟踪重建的第一步。代码是这样的。

#include <pcl/io/openni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <string>
using namespace std;
int total;
class SimpleOpenNIViewer
{
public:
SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}  
void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud)//被绑定的方法
{
double start=pcl::getTime();
if (!viewer.wasStopped())

static unsigned count=0;
 //test data
/*for (int i=0;i<(*cloud).size();i++)
{
cout<<(*cloud).points[i].data[0]<<endl;


}*/
if (++count==30)
{   
double now=pcl::getTime();
cout<<"time is"<< now <<endl;
char filename[100];
sprintf(filename,"F:\\TrackingData\\%d.pcd",total++);
pcl::io::savePCDFileASCII(filename,*cloud);              \\隔一段时间存储一张pcd文件
count=0;
}


 



         
           viewer.showCloud (cloud);
}

}


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


boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::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;
}

存了12张图片作为数据集先试试~加油啦~

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值