0

現在、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);
}
4

1 に答える 1

4
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);

(上記の私の答えも当てはまり、両方を行う必要があります!)

于 2012-05-26T20:08:51.067 に答える