【问题标题】:PCL 1.6: generate pcd files from each frame of a oni filePCL 1.6:从 oni 文件的每一帧生成 pcd 文件
【发布时间】:2014-02-01 23:01:10
【问题描述】:

我需要处理 ONI 文件的每一帧。现在我只想将file.oni 的每一帧保存在file.pcd 中。我关注这个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;
 }

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

【问题讨论】:

  • 我解决了删除代码行:PCL_INFO ("Wrote a cloud with %zu (%ux%u) points in %s.\n",cloud-&gt;size (), cloud-&gt;width, cloud-&gt;height, buf); 但我不明白为什么?你能帮我理解吗?函数 cloud_cb_ 是否调用了每一帧?

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


【解决方案1】:

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

【讨论】:

  • 但是我不明白这个函数的目的是什么:boost::this_thread::sleep (boost::posix_time::seconds (55));有人能帮我理解吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 2020-11-03
  • 1970-01-01
  • 1970-01-01
  • 2012-10-07
  • 2013-08-14
相关资源
最近更新 更多