简体   繁体   中英

How to use PCL to filter point cloud data from kinect

I am now working with PCL and kinect, the call back function is shown below:

I want to do some filtering but I can't access "cloud" in the callback function directly because it is constant type, so I copy it to "cloud2" to see if it works.

The result is compiling pass but run time error, any one help me?

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);
}
 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2; 

This only defines cloud2 , you need to also create it on the heap otherwise you will get bad memory access (as its a pointer).

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2( new pcl::PointCloud<pcl::PointXYZ>());

Also you shouldn't be doing

 *cloud2 = *cloud; 

This isn't a nice clean way of copying you should use.

pcl::copyPointCloud<PointT, PointT>(*cloud, *cloud2);

(My above answer applies also you should do both!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM