ch04-4.3.5 pcl中的OPenNI点云获取框架
1.代码
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <iostream>
//#include <pcl/io/openni_grabber.h>//版本不同,源码有误,改正如下:
#include <pcl/io/openni2_grabber.h>
#include <pcl/common/time.h>
using namespace std;
using namespace pcl;
//最终调试的结果是pcl::Grabber* interface =new pcl::OpenNIGrabber ();这句话中pcl::OpenNIGrabber ()是打开一种openni的外界设备,因为没有外界设备,所以调试出错
#ifdef _x64
# 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::OpenNIGrabber()版本不同,源码有误,改正如下:
//创建openni采集对象
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;
}
2.显示
最终调试的结果是pcl::Grabber interface =new pcl::OpenNIGrabber ();这句话中pcl::OpenNIGrabber ()是打开一种openni的外界设备,因为没有外界设备,所以调试出错