1

这是我到目前为止所拥有的,我想从中保存 pcd 文件我知道我必须做这样的事情,但不完全确定 pcl::PointCloud::PointPointXYZRGBA> cloud; pcl::io:;savePCDFileASCII("test.pcd",cloud);

我必须在我当前的代码中添加什么 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);
    }
4

1 回答 1

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

干得好。

于 2012-10-23T10:41:17.157 回答