从另一个标记的点云生成点云 [英] Generating a point cloud from another labeld point cloud

查看:126
本文介绍了从另一个标记的点云生成点云的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带标签的点云数据(云),它的点包括x"、y"、z"和标签"信息,而标签可以是 1,2 或 3.

I have a labeled point cloud data (cloud) that it's points include "x","y", "z" and "label" information while label can be 1,2 or 3.

pcl::PointCloud<pcl::PointXYZL>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZL>);

现在,我想根据标签将这个点云划分为 3 个独立的点云.例如,我想生成一个点云,它只包含标签为 1 (cloud1) 的那些点的 x、y、z 信息.我是这样做的:

Now, I want to divide this point cloud to 3 separate point cloud according to their label. for example I want to generate a point cloud which only includes the x,y,z information of those points which their label is 1 (cloud1). I did this:

int ll=0;

pcl::PointCloud<pcl::PointXYZL>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZL>);

for (int ii = 0; ii < cloud->points.size (); ++ii){
if(cloud->points[ii].label==1)
{

  cloud1->points[ll].x=cloud->points[ii].x;
  cloud1->points[ll].y=cloud->points[ii].y;
  cloud1->points[ll].z=cloud->points[ii].z;
  ll++;

}
}

for (int ii = 0; ii < cloud->points.size (); ++ii){
{

cloud1->points[ll].x=cloud->points[ii].x;
cloud1->points[ll].y=cloud->points[ii].y;
    cloud1->points[ll].z=cloud->points[ii].z;
ll++;
}
}

但是我收到了Segmentation fault (core dumped)" 错误.我想知道问题出在哪里?

But I received "Segmentation fault (core dumped)" error. I was wondering where is the problem?

推荐答案

您正在索引到尚无大小的 cloud1 存储向量.你不能这样做,因为 ll 超出了界限,这就是它出现分段错误的原因.您需要使用 push_back 附加一个新点.

You're indexing into cloud1 storage vector that doesn't have a size yet. You can't do that because ll is out of bounds, which is why it segmentation faults. You need to append a new point using push_back.

if (cloud->points[ii].label == 1)
{
  cloud1->push_back(cloud->points[ii]);
}

这篇关于从另一个标记的点云生成点云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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