PCL笔记三:点云连接;点云简单拼接

本文介绍了如何使用PCL库进行两种点云数据的拼接:同类型点云直接拼接和xyz点云与法线信息的融合。在直接拼接中,需要注意去重、排异和对齐等操作。在融合过程中,利用pcl::concatenateFields将点云的xyz坐标与法线信息结合成新的PointNormal类型点云。
摘要由CSDN通过智能技术生成

连接两个不同的点云为一个点云。两种情况:

  • 同种类型点云拼接:
  • 同样N个点的xyz和rgb拼接:或者xyz与Normal的拼接。

注意不同点云类型的转换。


第一种:同种类型点云直接拼接。

#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
using namespace std;



int main()
{
	pcl::PointCloud<pcl::PointXYZ>cloud_a, cloud_b, cloud_c;

	cerr << "Cloud A:" << endl;
	cloud_a.width = 5;
	cloud_a.height = cloud_b.height = 1;
	cloud_a.points.resize(cloud_a.width * cloud_a.height);
	for (size_t i = 0; i < cloud_a.size(); i++)
	{
		cloud_a.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud_a.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud_a.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
		cerr << " " << cloud_a.points[i].x << " " << cloud_a.points[i].y << " " << cloud_a.points[i].z << endl;
	}

	cerr << "Cloud B:" << endl;
	cloud_b.width = 3;
	cloud_b.points.resize(cloud_b.width * cloud_b.height);

	for (size_t i = 0; i < cloud_b.size(); i++)
	{
		cloud_b.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud_b.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud_b.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
		cerr << " " << cloud_b.points[i].x << " " << cloud_b.points[i].y << " " << cloud_b.points[i].z << endl;
	}

    cout << endl;
	cerr << "拼接之后:Cloud C:" << endl;
	cloud_c = cloud_a;
	cloud_c += cloud_b;   // 简单粗暴。
	for (size_t i = 0; i < cloud_c.size(); i++)
	{
		cerr << " " << cloud_c.points[i].x << " " << cloud_c.points[i].y << " " << cloud_c.points[i].z << endl;
	}
}

 输出:

Cloud A:
 1.28125 577.094 197.938
 828.125 599.031 491.375
 358.688 917.438 842.563
 764.5 178.281 879.531
 727.531 525.844 311.281
Cloud B:
 15.3438 93.5938 373.188
 150.844 169.875 1012.22
 456.375 121.938 4.78125

拼接之后:Cloud C:
 1.28125 577.094 197.938
 828.125 599.031 491.375
 358.688 917.438 842.563
 764.5 178.281 879.531
 727.531 525.844 311.281
 15.3438 93.5938 373.188
 150.844 169.875 1012.22
 456.375 121.938 4.78125

缺少去重,排异,对齐等操作。 



第二种:同样N个点的xyz和rgb拼接:或者xyz与Normal的拼接。

#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
using namespace std;


int main()
{
	pcl::PointCloud<pcl::PointXYZ>cloud_a;
	pcl::PointCloud<pcl::Normal>n_cloud_b;
	pcl::PointCloud<pcl::PointNormal> p_n_cloud_c;

	cerr << "Cloud A:" << endl;
	cloud_a.width = 5;
	cloud_a.height = n_cloud_b.height = 1;
	cloud_a.points.resize(cloud_a.width * cloud_a.height);
	for (size_t i = 0; i < cloud_a.size(); i++)
	{
		cloud_a.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud_a.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud_a.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
		cerr << " " << cloud_a.points[i].x << " " << cloud_a.points[i].y << " " << cloud_a.points[i].z << endl;
	}

	cerr << "Cloud B:" << endl;
	n_cloud_b.width = 5;
	n_cloud_b.points.resize(n_cloud_b.width * n_cloud_b.height);
	for (size_t i = 0; i < n_cloud_b.size(); i++)
	{
		n_cloud_b.points[i].normal[0] = 1024 * rand() / (RAND_MAX + 1.0f);
		n_cloud_b.points[i].normal[1] = 1024 * rand() / (RAND_MAX + 1.0f);
		n_cloud_b.points[i].normal[2] = 1024 * rand() / (RAND_MAX + 1.0f);
		cout << " " << n_cloud_b.points[i].normal[0] << " " << n_cloud_b.points[i].normal[1] << n_cloud_b.points[i].normal[2] << endl;
	}

	cout << endl;
	cout << "Cloud C:" << endl;
	pcl::concatenateFields(cloud_a, n_cloud_b, p_n_cloud_c);
	for (size_t i = 0; i < p_n_cloud_c.size(); i++)
	{
		cerr << " " << p_n_cloud_c.points[i].x << " " << p_n_cloud_c.points[i].y << " " << p_n_cloud_c.points[i].z
			<< " " << p_n_cloud_c.points[i].normal[0] << " " << p_n_cloud_c.points[i].normal[1]
			<< " " << p_n_cloud_c.points[i].normal[2] << endl;
	}
}

 cloud_b可以看作法线或者RGB等信息。

Cloud A:
 1.28125 577.094 197.938
 828.125 599.031 491.375
 358.688 917.438 842.563
 764.5 178.281 879.531
 727.531 525.844 311.281
Cloud B:
 15.3438 93.5938373.188
 150.844 169.8751012.22
 456.375 121.9384.78125
 9.125 386.938544.406
 584.875 616.188621.719

Cloud C:
 1.28125 577.094 197.938 15.3438 93.5938 373.188
 828.125 599.031 491.375 150.844 169.875 1012.22
 358.688 917.438 842.563 456.375 121.938 4.78125
 764.5 178.281 879.531 9.125 386.938 544.406
 727.531 525.844 311.281 584.875 616.188 621.719


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值