我已经使用 PCL 几天了,但无法解决一个问题: 我得到了一个密集的、有组织的
PointCloud<PointT> cloud_1
,并且想要用处理过的点填充第二个新的 PointCoud
PointCloud<PointT> cloud_2
。
所以我的想法是(用伪代码,但如果有帮助的话我当然可以提供 MWE):
//cloud_1 is also a Ptr that gets a Cloud loaded from PCD File
PointCloud<PointT>::Ptr cloud_2(new PointCloud<PointT>)
void populateSecondCoud(PointCloud<PointT>& cloud_1, PointCloud<PointT>& cloud_2){
cloud_2.width = cloud_1.width;
cloud_2.height = cloud_1.height;
for (i in cloud_1.height){
for(j in cloud_1.width){
PointT p = cloud_1.at(i,j);
// do processing with the point...
cloud_2.at(i,j) = p
}
}
}
populateSecondCloud(*cloud_1, *cloud_2)
以 :
结束terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
我猜,因为
cloud_2
的点向量仍然完全是空的。
有什么方法可以迭代地填充有组织的PointCloud
?
所有这些都会发生在很多
PointCloud
上,这就是为什么我在处理点之前尝试阻止从 cloud_2
复制 cloud_1
。
任何想法都将不胜感激。当然我可以提供一个编译代码片段,但我认为从上面的伪代码可以清楚地看出问题。
编辑:澄清了
cloud_2
如何初始化。
您的代码中有 2 个问题:
1。内存分配:
您需要分配适当大小的
cloud_2
。pcl::PointCloud
构造函数,它接受宽度和高度并相应地分配数据,例如:
PointCloud<PointT>::Ptr cloud_2 = PointCloud<PointT>::Ptr cloud(
new PointCloud<PointT>(cloud_1.width, cloud_1.height));
pcl::PointCloud::resize
方法调整 cloud_2
的大小,并在 populateSecondCoud
中添加新的宽度和高度:
cloud_2.resize(cloud_1.width, cloud_1.height);
pcl::PointCloud::at
文档、at
的参数是 column, row(按此顺序)。i
和列索引中的 j
。
因此更改包含以下内容的行:
at(i, j)
致:
at(j, i)