繁体   English   中英

来自C ++文件的Wrtie数据(点云库)

[英]Wrtie Data from C++ File (Point Cloud Library)

我正在使用点云库来获取深度图,然后每隔一秒左右将PCD文件写入内存,以便其他程序可以拾取它。

我让程序正确地使用可视化工具渲染深度图,除了实际写入文件的一行外,它都可以工作。

这是我的代码:

 #include <pcl/io/openni_grabber.h>
 #include <iostream>
 #include <pcl/io/pcd_io.h>
 #include <pcl/visualization/cloud_viewer.h>

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

     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
     {
       if (!viewer.wasStopped())
         viewer.showCloud (cloud);
         //this is the line to write the file.
         //I am not sure it is the correct location.
         pcl::io::savePCDFileASCII ("test_pcd_here.pcd", cloud);
     }

     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;
 }

这是我在尝试编写文件时遇到的错误:

/home/patrick/Desktop/kinect/grabber/openni_grabber.cpp: In member function ‘void SimpleOpenNIViewer::cloud_cb_(const ConstPtr&)’:
/home/patrick/Desktop/kinect/grabber/openni_grabber.cpp:15:59: error: no matching function for call to ‘savePCDFileASCII(const char [18], const ConstPtr&)’
/home/patrick/Desktop/kinect/grabber/openni_grabber.cpp:15:59: note: candidate is:
/usr/include/pcl-1.6/pcl/io/pcd_io.h:704:5: note: template<class PointT> int pcl::io::savePCDFileASCII(const string&, const pcl::PointCloud<PointT>&)
make[2]: *** [CMakeFiles/openni_grabber.dir/openni_grabber.cpp.o] Error 1
make[1]: *** [CMakeFiles/openni_grabber.dir/all] Error 2
make: *** [all] Error 2

savePCDFileASCII()函数在提供指针时期望对PointCloud进行const引用。 你必须取消引用指针:

pcl::io::savePCDFileASCII ("test_pcd_here.pcd", *cloud);

请记住,您的回调函数会尽可能频繁地触发(超过每秒一次),因此您可能希望限制导出。 更重要的是,如果您尝试在其他程序正在读取数据时(或者反过来)写入数据,则任一程序都可能崩溃(竞争条件),因此您需要某种形式的同步或直接通过其他方式流式传输PointCloud装置(例如插座或管道)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM