首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >利用点云库存储Kinect中的点云

利用点云库存储Kinect中的点云
EN

Stack Overflow用户
提问于 2012-07-23 01:59:31
回答 3查看 5.9K关注 0票数 2

使用Ubuntu上的,我尝试从Kinect中获取多个点云,并将它们存储在内存中,供以后在程序中使用。我的代码显示在这篇文章的底部是为了存储来自Kinect的第一个Point并输出它的宽度和高度。程序给出了一个运行时错误:

代码语言:javascript
复制
/usr/include/boost/smart_ptr/shared_ptr.hpp:418: T* boost::shared_ptr<T>::operator->() const [with T = pcl::PointCloud<pcl::PointXYZ>]: Assertion `px != 0' failed.

所有的帮助都非常感谢,我总是接受一个答案!

守则:

代码语言:javascript
复制
  #include <pcl/io/openni_grabber.h>
  #include <pcl/visualization/cloud_viewer.h>

 class SimpleOpenNIViewer
 {
  public:
  SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}

 pcl::PointCloud<pcl::PointXYZ>::Ptr prevCloud;


  void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
  {


if (!viewer.wasStopped())
   viewer.showCloud (cloud);


//ICP start
if(!prevCloud) {
    pcl::PointCloud<pcl::PointXYZ>::Ptr prevCloud( new pcl::PointCloud<pcl::PointXYZ>());

    pcl::copyPointCloud<pcl::PointXYZ, pcl::PointXYZ>(*cloud, *prevCloud);
}

cout << prevCloud->width << " by " << prevCloud->height << endl; 



  }

  void run ()
  {
    pcl::Grabber* interface = new pcl::OpenNIGrabber();

    boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
      boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);


    interface->registerCallback (f);

    interface->start ();


    while (!viewer.wasStopped())
    {
      boost::this_thread::sleep (boost::posix_time::seconds (1));
    }

    interface->stop ();
  }

  pcl::visualization::CloudViewer viewer;
 };

  int main ()
{
 SimpleOpenNIViewer v;
 v.run ();
 return 0;
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-07-25 18:07:25

试试这个,我没有安装Kinect驱动程序,所以我无法测试。基本上,在我的版本中,prevCloud是在构造函数中实例化的,因此(!prevCloud)总是等于'false‘。这就是说prevCloud.get() != NULL

代码语言:javascript
复制
#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>

class SimpleOpenNIViewer
{
typedef pcl::PointXYZ                           Point;
typedef pcl::PointCloud<Point>                  PointCloud;
public:
SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {
        prevCloud = PointCloud::Ptr(NULL);
    }

void cloud_cb_ (const PointCloud::ConstPtr &cloud)
{
    if (!viewer.wasStopped())
        viewer.showCloud (cloud);
            if (!prevCloud) // init previous cloud if first frame
                    prevCloud = PointCloud::Ptr(new PointCloud);
            else.   // else RunICP between cloud and prevCloud
                    //RunICP(cloud,prevCloud);

            //Copy new frame in to prevCloud
    pcl::copyPointCloud<Point, Point>(*cloud, *prevCloud);
    cout << prevCloud->width << " by " << prevCloud->height << endl; 
}

void run ()
{
    pcl::Grabber* interface = new pcl::OpenNIGrabber();

    boost::function<void (const PointCloud::ConstPtr&)> f =
    boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);

    interface->registerCallback (f);
    interface->start ();


    while (!viewer.wasStopped())
    {
        boost::this_thread::sleep (boost::posix_time::seconds (1));
    }

    interface->stop ();
}

PointCloud::Ptr prevCloud;
pcl::visualization::CloudViewer viewer;
};

int main ()
{
SimpleOpenNIViewer v;
v.run ();
return 0;
}
票数 2
EN

Stack Overflow用户

发布于 2012-07-23 02:11:25

您正在创建一个新的局部变量prevCloud并将cloud复制到其中,而不是复制到prevCloud字段中。因此,如果字段的值在if {}之前为null,则在if {}之后仍然为null,因此当您试图取消引用它时,它会抛出一个错误。

票数 0
EN

Stack Overflow用户

发布于 2012-08-15 14:49:40

也许这段代码可以帮你,云是保存在一个"pcd“文件,看看这里

其他选择是与PCL的"Kinfu“项目合作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11605594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档