2012-10-17 65 views
1

這是我到目前爲止,我想從它保存pcd文件 我知道我必須做這樣的事情,但不完全確定 pcl :: PointCloud :: PointPointXYZRGBA> cloud; pcl :: io:; savePCDFileASCII(「test.pcd」,cloud);PCL創建一個pcd雲

我有什麼在以後會有test.pcd 感謝

#include <pcl/point_cloud.h> 
    #include <pcl/point_types.h> 
    #include <pcl/io/openni_grabber.h> 
    #include <pcl/visualization/cloud_viewer.h> 
    #include <pcl/common/time.h> 

    class SimpleOpenNIProcessor 
    { 
     public: 
      SimpleOpenNIProcessor() : viewer ("PCL OpenNI Viewer") {} 
      void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud) 
      { 
       static unsigned count = 0; 
       static double last = pcl::getTime(); 
       if (++count == 30) 
       { 
        double now = pcl::getTime(); 
        std::cout << "distance of center pixel :" << cloud->points [(cloud->width >> 1) * (cloud->height + 1)].z << " mm. Average framerate: " << double(count)/double(now - last) << " Hz" << std::endl; 
        count = 0; 
        last = now; 
       } 
       if (!viewer.wasStopped()) 
        viewer.showCloud (cloud); 
      } 

      void run() 
      { 
       // create a new grabber for OpenNI devices 
       pcl::Grabber* interface = new pcl::OpenNIGrabber(); 

       // make callback function from member function 
       boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f = 
        boost::bind (&SimpleOpenNIProcessor::cloud_cb_, this, _1); 

       // connect callback function for desired signal. In this case its a point cloud with color values 
       boost::signals2::connection c = interface->registerCallback (f); 

       // start receiving point clouds 
       interface->start(); 

       // wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1); 
       while (true) 
        boost::this_thread::sleep (boost::posix_time::seconds (1)); 

       // stop the grabber 
       interface->stop(); 
      } 

      pcl::visualization::CloudViewer viewer; 
    }; 

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

回答

2
#include <iostream> 
#include <string> 
#include <sstream> 

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

using namespace std; 

const string OUT_DIR = "D:\\frame_saver_output\\"; 

class SimpleOpenNIViewer 
{ 
public: 
    SimpleOpenNIViewer() : viewer ("PCL Viewer") 
    { 
       frames_saved = 0; 
       save_one = false; 
    } 

    void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &cloud) 
    { 
       if (!viewer.wasStopped()) { 
         viewer.showCloud (cloud); 

         if(save_one) { 
           save_one = false; 
           std::stringstream out; 
           out << frames_saved; 
           std::string name = OUT_DIR + "cloud" + out.str() + ".pcd"; 
           pcl::io::savePCDFileASCII(name, *cloud); 
         } 
       } 
    } 

    void run() 
    { 
       pcl::Grabber* interface = new pcl::OpenNIGrabber(); 

       boost::function<void (const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr&)> f = 
         boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1); 

       interface->registerCallback (f); 

       interface->start(); 

       char c; 

       while (!viewer.wasStopped()) 
       { 
         //sleep (1); 

         c = getchar(); 
         if(c == 's') { 
           cout << "Saving frame " << frames_saved << ".\n"; 
           frames_saved++; 
           save_one = true; 
         } 
       } 

       interface->stop(); 
     } 

     pcl::visualization::CloudViewer viewer; 

     private: 
       int frames_saved; 
       bool save_one; 

}; 

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

在這裏你去我當前的代碼添加。