PCL创建一个pcd云

时间:2012-10-17 02:04:46

标签: kinect point-clouds point-cloud-library

这是我到目前为止,我想从中保存pcd文件 我知道我必须做这样的事情,但不完全确定 PCL ::点云:: PointPointXYZRGBA>云; PCL :: IO:; savePCDFileASCII( “test.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);
    }

1 个答案:

答案 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; 
} 

你走了。