PCL 1.6:从oni文件的每个帧生成pcd文件

时间:2014-01-14 00:43:18

标签: visual-c++ openni point-cloud-library

我需要处理ONI文件的每一帧。现在我只想在file.pcd中保存file.oni的每一帧。我遵循这个code但它只适用于PCL 1.7并且我使用的是v1.6。  所以我以这种方式改变了一些代码

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

    #include <pcl/point_cloud.h>
    #include <pcl/point_types.h>
    #include <pcl/io/oni_grabber.h>
    #include <pcl/io/pcd_io.h>
    #include <vector>
    int i = 0;
     char buf[4096];

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

     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
     {
       //if (!viewer.wasStopped())
        //{
        // viewer.showCloud (cloud);
         pcl::PCDWriter w;
         sprintf (buf, "frame_%06d.pcd", i);
         w.writeBinaryCompressed (buf, *cloud);
         PCL_INFO ("Wrote a cloud with %zu (%ux%u) points in %s.\n",cloud->size (), cloud->width, cloud->height, buf);
         ++i;
        //}

     }

     void run ()
     {
       pcl::Grabber* interface = new pcl::OpenNIGrabber("file.oni");

       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));
           }
       PCL_INFO ("Successfully processed %d frames.\n", i);
       interface->stop ();
     }

     pcl::visualization::CloudViewer viewer;
 };

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

但是当我运行它时会崩溃。为什么呢?

1 个答案:

答案 0 :(得分:0)

我解决了从ONI文件中获取每个帧的问题。我需要在触发模式下使用ONIGrabber功能集。

这是修改后的代码:

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

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/oni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <vector>

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

 void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
 {
   //if (!viewer.wasStopped())
    //{
    // viewer.showCloud (cloud);
     pcl::PCDWriter w;
     sprintf (buf, "frame_%06d.pcd", i);
     w.writeBinaryCompressed (buf, *cloud);
     PCL_INFO ("Wrote a cloud with %zu (%ux%u) points in %s.\n",cloud->size (),     
cloud->width, cloud->height, buf);
     ++i;
    //}

 }

 void run ()
 {
   pcl::Grabber* interface = new pcl::ONIGrabber("file.oni",false,false); //set for trigger

   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())
       {
        interface->start()//to update each frame from the oni file 
        boost::this_thread::sleep (boost::posix_time::seconds (1));
       }
   PCL_INFO ("Successfully processed %d frames.\n", i);
   interface->stop ();
 }

 pcl::visualization::CloudViewer viewer;
 };

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