OpenNI Grabber Framework in PCL代码更新(适用于pcl_12.0)

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);
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值