【pcl入门教程系列】之点云Concatenate

简要说明

  点云拼接(Concatenate)是指将点云进行累加在一起,只是累加的方式不太一样。一种是点云的字段与维度完全一致,数量可以不同,两部分点云相加,点云的数量增加了。另一种是点云的字段与维度不一致,但是两部分点云的数量相同,进行维度的累加。举例简单阐述一下:

  针对第一种累加情况:假设点云A有N个点,每个点数据PointXYZ,点云B有M个点,每个点的数据PointXYZ,那么进行累加后点云C有(N+M)个点,每个点的数据PointXYZ。

【pcl入门教程系列】之点云Concatenate_第1张图片

  针对第二种累加情况:假设点云A有N个点,每个点数据PointXYZ,点云B有N个点,每个点的数据PointRGB,那么进行累加后点云C有(N)个点,每个点的数据PointXYZRGB。

【pcl入门教程系列】之点云Concatenate_第2张图片
代码官方Demo示例
#include 
#include 
#include 

int main (int argc, char** argv)
{
  if (argc != 2)
  {
    std::cerr << "please specify command line arg '-f' or '-p'" << std::endl;
    exit(0);
  }
  pcl::PointCloud<pcl::PointXYZ> cloud_a, cloud_b, cloud_c;
  pcl::PointCloud<pcl::Normal> n_cloud_b;
  pcl::PointCloud<pcl::PointNormal> p_n_cloud_c;

  // Fill in the cloud data
  cloud_a.width  = 5;
  cloud_a.height = cloud_b.height = n_cloud_b.height = 1;
  cloud_a.points.resize (cloud_a.width * cloud_a.height);
  if (strcmp(argv[1], "-p") == 0)
  {
    cloud_b.width  = 3;
    cloud_b.points.resize (cloud_b.width * cloud_b.height);
  }
  else{
    n_cloud_b.width = 5;
    n_cloud_b.points.resize (n_cloud_b.width * n_cloud_b.height);
  }

  for (std::size_t i = 0; i < cloud_a.size (); ++i)
  {
    cloud_a[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud_a[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud_a[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }
  if (strcmp(argv[1], "-p") == 0)
    for (std::size_t i = 0; i < cloud_b.size (); ++i)
    {
      cloud_b[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
      cloud_b[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
      cloud_b[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
    }
  else
    for (std::size_t i = 0; i < n_cloud_b.size (); ++i)
    {
      n_cloud_b[i].normal[0] = 1024 * rand () / (RAND_MAX + 1.0f);
      n_cloud_b[i].normal[1] = 1024 * rand () / (RAND_MAX + 1.0f);
      n_cloud_b[i].normal[2] = 1024 * rand () / (RAND_MAX + 1.0f);
    }
  std::cerr << "Cloud A: " << std::endl;
  for (std::size_t i = 0; i < cloud_a.size (); ++i)
    std::cerr << "    " << cloud_a[i].x << " " << cloud_a[i].y << " " << cloud_a[i].z << std::endl;

  std::cerr << "Cloud B: " << std::endl;
  if (strcmp(argv[1], "-p") == 0)
    for (std::size_t i = 0; i < cloud_b.size (); ++i)
      std::cerr << "    " << cloud_b[i].x << " " << cloud_b[i].y << " " << cloud_b[i].z << std::endl;
  else
    for (std::size_t i = 0; i < n_cloud_b.size (); ++i)
      std::cerr << "    " << n_cloud_b[i].normal[0] << " " << n_cloud_b[i].normal[1] << " " << n_cloud_b[i].normal[2] << std::endl;

  // Copy the point cloud data
  if (strcmp(argv[1], "-p") == 0)
  {
    cloud_c  = cloud_a;
    cloud_c += cloud_b;
    std::cerr << "Cloud C: " << std::endl;
    for (std::size_t i = 0; i < cloud_c.size (); ++i)
      std::cerr << "    " << cloud_c[i].x << " " << cloud_c[i].y << " " << cloud_c[i].z << " " << std::endl;
  }
  else
  {
    pcl::concatenateFields (cloud_a, n_cloud_b, p_n_cloud_c);
    std::cerr << "Cloud C: " << std::endl;
    for (std::size_t i = 0; i < p_n_cloud_c.size (); ++i)
      std::cerr << "    " <<
        p_n_cloud_c[i].x << " " << p_n_cloud_c[i].y << " " << p_n_cloud_c[i].z << " " <<
        p_n_cloud_c[i].normal[0] << " " << p_n_cloud_c[i].normal[1] << " " << p_n_cloud_c[i].normal[2] << std::endl;
  }
  return (0);
}

直接贴上官方的demo代码,比较简单就不多做解释。下面简单介绍一下维度累加的函数:

bool pcl::concatenateFields(const pcl::PCLPointCloud2& cloud1_in,
                            const pcl::PCLPointCloud2& cloud2_in,
                            pcl::PCLPointCloud2& cloud_out);


template<typename PointIn1T, typename PointIn2T, typename PointOutT>
void pcl::concatenateFields(const pcl::PointCloud<PointIn1T>& cloud1_in,
                            const pcl::PointCloud<PointIn2T>& cloud2_in,
                            pcl::PointCloud<PointOutT>& cloud_out);	

附:如果输入两个点云数据集具有重叠的字段,那么第二个点云中的数据将覆盖第一个点云中的数据。

小结

  从上数官方demo代码可以看出,第一种累加情况只是两个点云数据集进行字符式 A + B A+B A+B相加即可,第二种维度相加需要使用pcl::concatenateFields()函数进行维度相加。点云数据连接在增加点云的数据信息量,因此pcl::concatenateFields()函数一般在提取点云每个点信息时候可以使用该函数保存多个维度的点信息。ok,本篇博文就说这么多,如有错误,还请批评指正。

参考

https://pcl.readthedocs.io/projects/tutorials/en/latest/concatenate_clouds.html#concatenate-clouds

你可能感兴趣的:(自动驾驶技术专栏,PCL,点云Concatenate)