在Ubuntu上使用Point Cloud Library,我试图从Kinect中获取多个点 Cloud 并将它们存储在内存中以供以后在程序中使用 . 我在本文底部显示的代码旨在存储Kinect中的第一个Point Cloud并输出其宽度和高度 . 该程序给我一个运行时错误:
/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.
All help is greatly appreciated and I always accept an answer!
代码:
#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;
}
3 回答
试试这个,我不测试 . 基本上在我的版本中,prevCloud在构造函数中实例化,因此
(!prevCloud)
将始终等于'false' . 这就是说prevCloud.get() != NULL
.您正在创建一个新的局部变量
prevCloud
并将cloud
复制到其中,而不是复制到prevCloud
字段中 . 因此,如果字段的值在if {}
之前为null,则在if {}
之后它仍然为null,因此当您尝试取消引用它时会抛出错误 .可能是这段代码可以帮到你, Cloud 端保存在"pcd"文件中,看看here
其他选择是与PCL的“Kinfu”项目合作