我现在正在使用 PCL 和 kinect,回调函数如下图所示:
我想做一些过滤,但是我不能直接在回调函数中访问“cloud”,因为它是常量类型,所以我把它复制到“cloud2”看看它是否有效。
结果是编译通过但运行时错误,有人帮助我吗?
class SimpleOpenNIProcessor
{
public:
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2;
SimpleOpenNIProcessor () : viewer ("PCL OpenNI Viewer") {}
void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
{
*(cloud2)=*(cloud);
if (!viewer.wasStopped())
viewer.showCloud (cloud);
}
void run ()
{
// create a new grabber for OpenNI devices
pcl::Grabber* interface = new pcl::OpenNIGrabber();
// make callback function from member function
boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
boost::bind (&SimpleOpenNIProcessor::cloud_cb_, this, _1);
// connect callback function for desired signal. In this case its a point cloud with color values
boost::signals2::connection c = interface->registerCallback (f);
// start receiving point clouds
interface->start ();
// wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1);
while (true)
sleep(1);
// stop the grabber
interface->stop ();
}
pcl::visualization::CloudViewer viewer;
};
int main ()
{
SimpleOpenNIProcessor v;
v.run ();
return (0);
}