编写点云代码出错 using ptr=pcl

error: ‘using Ptr = pcl::shared_ptr >’ {aka ‘class boost::shared_ptr >’} has no member named ‘push_back’
  222 |                     plane.push_back(point1);
      |                           ^~~~~~~~~


代码如下

void PlaneGroundFilter::devide_plane(const pcl::PointCloud &p_sorted,double& x_boundary,
 pcl::PointCloud::Ptr plane,
 pcl::PointCloud::Ptr slope_plane)
    {

            for (int i = 0; i < p_sorted.points.size(); i++){
                int x = p_sorted.points[i].x;
                int y = p_sorted.points[i].y;
                int z = p_sorted.points[i].z;
                if (x < x_boundary){
                    pcl::PointXYZ point1;
                    point1.x = x;
                    point1.y = y;
                    point1.z = z;
                    plane.push_back(point1);
                }
                else{
                    pcl::PointXYZ point2;
                    point2.x = x;
                    point2.y = y;
                    point2.z = z;
                    slope_plane.push_back(point2);
                }
            }
 }

该回答通过自己思路及引用到各个渠道搜索综合及思考,得到内容具体如下:

报错信息显示,plane和slope_plane都是pcl::PointCloud<VPoint>::Ptr类型的智能指针,而不是直接的PointCloud对象,因此不能使用push_back方法。正确的方法是使用pcl::PointCloud<VPoint>的push_back方法。

具体修改后的代码如下所示:

void PlaneGroundFilter::devide_plane(const pcl::PointCloud<VPoint> &p_sorted,double& x_boundary,
 pcl::PointCloud<VPoint>::Ptr plane,
 pcl::PointCloud<VPoint>::Ptr slope_plane)
    {
 
            for (int i = 0; i < p_sorted.points.size(); i++){
                int x = p_sorted.points[i].x;
                int y = p_sorted.points[i].y;
                int z = p_sorted.points[i].z;
                if (x < x_boundary){
                    VPoint point1;
                    point1.x = x;
                    point1.y = y;
                    point1.z = z;
                    plane->push_back(point1);
                }
                else{
                    VPoint point2;
                    point2.x = x;
                    point2.y = y;
                    point2.z = z;
                    slope_plane->push_back(point2);
                }
            }
 }

在上面的代码中,我们使用了plane->push_back和slope_plane->push_back方法来添加点到PointCloud对象中。另外,我们还将pcl::PointXYZ改为了VPoint,这是因为在函数参数中传入的点云类型为VPoint,而不是pcl::PointXYZ。


如果以上回答对您有所帮助,点击一下采纳该答案~谢谢

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^