PCL如何创建Point Cloud数组/向量?

时间:2015-04-29 08:56:52

标签: c++ eigen point-cloud-library

我在hdd上存储了85点云。我想打开所有的云并将它们保存在矢量/数组中 我该怎么做?

我测试的没有成功:

    define _CRT_SECURE_NO_WARNINGS
    #include <pcl/io/pcd_io.h>
    #include <pcl/point_types.h>
    #include <pcl/registration/icp.h>
    #include <pcl/visualization/pcl_visualizer.h>
    #include <pcl/common/transforms.h>
    #include <pcl/filters/voxel_grid.h>
    #include <pcl/filters/radius_outlier_removal.h>

    #include <Eigen/Geometry>


    #include <iostream>
    #include <string>

    using namespace pcl;
    using namespace std;

    int main(int argc, char** argv)
    {
    //Create Point Clouds
    PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);

    vector < PointCloud<PointXYZ>::Ptr, Eigen::aligned_allocator <PointCloud <PointXYZ>::Ptr > > sourceClouds;

    //save PointClouds to array
    for (int i = 1; i < (argc - 1); i++)
    {
        if (io::loadPCDFile<PointXYZ>(argv[i], *sourceCloud) != 0)
        {
            return -1;
        }
        cout << "Loaded file " << argv[i] << " (" << sourceCloud->size() << " points)" << endl;
        sourceClouds.push_back(sourceCloud);
        cout << "Point Cloud " << i-1 << "has got " << sourceClouds[i-1]->size() << " Points" << endl;
        sourceCloud->clear();
    }

    for (int i = 0; i < sourceClouds.size() - 1; i++)
    {
        cout << "Point Cloud " << i << "has got " << sourceClouds[i]->size() << " Points" << endl;
    }
    }

在第一个for循环中,来自两个Clouuds的PointCloudSize是相同的,但在第二个for循环中,PointCloudSize为0。 我做错了什么?

1 个答案:

答案 0 :(得分:2)

sourceClouds.push_back(sourceCloud);

此行仅复制PointCloud :: Ptr,不复制点云数据。

试试这个:

  int main(int argc, char** argv)
    {
    //Create Point Clouds
    //PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);

    vector < PointCloud<PointXYZ>::Ptr, Eigen::aligned_allocator <PointCloud <PointXYZ>::Ptr > > sourceClouds;

    //save PointClouds to array
    for (int i = 1; i < (argc - 1); i++)
    {
        PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);
        if (io::loadPCDFile<PointXYZ>(argv[i], *sourceCloud) != 0)
        {
            return -1;
        }
        cout << "Loaded file " << argv[i] << " (" << sourceCloud->size() << " points)" << endl;
        sourceClouds.push_back(sourceCloud);
        cout << "Point Cloud " << i-1 << "has got " << sourceClouds[i-1]->size() << " Points" << endl;
       // sourceCloud->clear();
    }

    for (int i = 0; i < sourceClouds.size() - 1; i++)
    {
        cout << "Point Cloud " << i << "has got " << sourceClouds[i]->size() << " Points" << endl;
    }
    }