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

Visual c++ PCL 1.6:从oni文件的每个帧生成pcd文件,visual-c++,openni,point-cloud-library,Visual C++,Openni,Point Cloud Library,我需要处理ONI文件的每一帧。现在我只想将file.oni的每一帧保存在file.pcd中。我遵循这一点,但它只适用于PCL1.7,我使用的是v1.6。 所以我用这种方式对代码做了一些修改 #include <pcl/io/openni_grabber.h> #include <pcl/visualization/cloud_viewer.h> #include <pcl/point_cloud.h> #include <

我需要处理ONI文件的每一帧。现在我只想将file.oni的每一帧保存在file.pcd中。我遵循这一点,但它只适用于PCL1.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;
 }

但当我运行它时,它崩溃了。为什么?

我解决了从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;
 }`

我解决了删除代码行的问题:PCL_INFO在%s中编写了一个包含%zu%ux%u个点的云。\n,cloud->size,cloud->width,cloud->height,buf;但我不明白为什么?你能帮我理解吗?该函数是否会对每个帧进行云计算?但我不明白该函数的目的是什么:boost::this_thread::sleep boost::posix_time::seconds 55;有人能帮我理解吗?