【问题标题】:How to use PCL to filter point cloud data from kinect如何使用 PCL 过滤来自 kinect 的点云数据
【发布时间】:2012-05-25 03:41:03
【问题描述】:

我现在正在使用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);
}

【问题讨论】:

    标签: kinect point-cloud-library


    【解决方案1】:
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2;
    

    这仅定义cloud2,您还需要在堆上创建它,否则您将获得错误的内存访问(作为它的指针)。

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

    你也不应该这样做

    *cloud2 = *cloud;
    

    这不是您应该使用的干净的复制方式。

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

    (我上面的答案也适用,你应该两者都做!)

    【讨论】:

    • 欢迎来到 Stack Overflow!要解决您在模板中看到的格式问题,您需要确保使用编辑器上的 {} 按钮将代码标记为这样。不过我现在已经为你编辑了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多