2014-01-14 18 views
1

我需要處理每個ONI文件的幀。現在我只想將file.oni的每個幀保存在file.pcd中。我遵循此code,但它只適用於PCL 1.7,我使用v1.6。 所以我改了一下代碼以這種方式PCL 1.6:從一個oni文件的每個幀生成pcd文件

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

但是當我運行它,它崩潰。爲什麼?

+0

我解決刪除代碼行:'PCL_INFO( 「寫了雲用%つ(%UX%U)在%s點\ n」。,雲> size(),cloud-> width,cloud-> height,buf);'但我不明白爲什麼?你能幫我理解嗎?函數cloud_cb_是否調用每個幀? – SPS

回答

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; 
}` 
+0

但我不明白這個函數的目的是什麼:'boost :: this_thread :: sleep(boost :: posix_time :: seconds(55));'有人能幫我理解嗎? – SPS

相關問題