检查代码boostshared_ptrpclPointCloudpclPointXYZRGB cloudPtr2new pclPointCloudpclPointXYZRGB; for const auto& point cloud遍历每一条叶片的所有点 访问当前点的坐标和颜色 PointXYZRGB P1; P1x = pointx; P1y = pointy; P
代码的语法和逻辑上都没有明显错误,但是存在一些潜在的问题和改进的空间:
- 在创建
boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB>>时,没有为其分配内存空间,应该修改为:
boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB>> cloudPtr2(new pcl::PointCloud<pcl::PointXYZRGB>());
- 在遍历点云
cloud的过程中,每次都将newIndices.indices清空两次,可能是一个错误,应该修改为:
newIndices.indices.clear();
//从被切片点云提取对应的值,即索引
if (sliceMap11.find(key1) != sliceMap11.end())
{
value = sliceMap11[key1].index;
std::cout << "Key: " << key1 << ", Value: " << value << std::endl;
newIndices.indices.insert(newIndices.indices.end(), value.indices.begin(), value.indices.end());//将所有提取到的叶片索引都加到了newIndices
}
- 在将索引对应的点云数据提取到
cloudPtr2时,每次都将newIndices.indices清空两次,可能是一个错误,应该修改为:
for (const auto& index1 : newIndices.indices)
{
pcl::PointXYZRGB point11;
point11.x = cloud77->points[index1].x;
point11.y = cloud77->points[index1].y;
point11.z = cloud77->points[index1].z;
cloudPtr2->points.push_back(point11);
}
newIndices.indices.clear();
- 在遍历完点云后,将
cloudPtr2添加到yezi中,但是并没有清空cloudPtr2,可能会导致yezi中的元素指向同一块内存空间,应该在添加后清空cloudPtr2:
yezi.push_back(cloudPtr2);
cloudPtr2->clear();
以上是对代码的检查和改进,希望能帮助到您
原文地址: https://www.cveoy.top/t/topic/iag7 著作权归作者所有。请勿转载和采集!