PCL官方的代码运行不了,这里进行了一些修改并在代码里进行了注释
#include <pcl/io/openni2_grabber.h>//原来是openni_grabber.h
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/common/time.h>
using namespace std::chrono_literals;
class SimpleOpenNIViewer
{
public:
void cloud_cb_(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& cloud)
{
static unsigned count = 0;
static double last = pcl::getTime();
if (++count == 30)
{
double now = pcl::getTime();
std::cout<<"distance of center pixel: "<<cloud->points[(cloud->width >> 1)*(cloud->height + 1)].z
<< " mm. Average framerate: " << double(count) / double(now - last) << " Hz" << std::endl;
count = 0;
last = now;
}
}
void run()
{
pcl::Grabber* interface = new pcl::io::OpenNI2Grabber();//原来是OpenNIGrabber();
std::function<void(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f =
[this](const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& cloud)
{
cloud_cb_(cloud);
};
boost::signals2::connection c = interface->registerCallback (f);
interface->start();
while (true)
std::this_thread::sleep_for(1s);
interface->stop();
}
};
int main()
{
SimpleOpenNIViewer v;
v.run();
return(0);
}