PCL创建pcd云 [英] PCL create a pcd cloud

查看:325
本文介绍了PCL创建pcd云的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is what I have so far and I want to save pcd file from it I know I have to do something like this but not exactly sure pcl::PointCloud::PointPointXYZRGBA> cloud; pcl::io:;savePCDFileASCII("test.pcd",cloud);

我必须在我当前的代码中添加什么,我将拥有test.pcd 谢谢

what do i have to add in my current code that i will have test.pcd Thanks

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

推荐答案

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

您在这里.

这篇关于PCL创建pcd云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆