在Ubuntu上使用點雲庫,我試圖從Kinect中取多個點雲並將它們存儲在內存中供以後在程序中使用。我在這篇文章底部顯示的代碼旨在存儲來自Kinect的第一個點雲並輸出其寬度和高度。該計劃給了我一個運行時錯誤:使用點雲庫來存儲來自Kinect的點雲
/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.
所有幫助是極大的讚賞,我總是接受一個答案!
代碼:
#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;
}
我得到一系列640x480的,所以這似乎做它應該做的。但是,我試圖在if(!prevCloud)塊中封裝copyPointCloud語句,但後來我得到了一系列0x0。任何想法爲什麼? – danielmhanover 2012-07-26 02:18:56
http://stackoverflow.com/questions/7226801/how-does-shared-ptr-work-in-if-condition可能會有所幫助。基本上在我的版本prevCloud是在構造函數中實例化的,所以(!prevCloud)將永遠等於'false'。也就是說prevCloud.get()!= NULL。 – Jerdak 2012-07-26 02:57:35
我想出了一個臨時解決方案:if(prevCloud-> width == 0),但這顯然更像是一種解決方法。你知道更具體的解決方案嗎? – danielmhanover 2012-07-26 03:28:02