0

I would like to find out what I am doing wrong.

Steps

  1. Load .pcd inout file
  2. Limit that input file as follow

    typename pcl::PointCloud<PointT>::Ptr cloudROI (new pcl::PointCloud<PointT>); 
    pcl::CropBox<PointT> region(true);
    region.setMin(Eigen::Vector4f (-10, -5, -2, 1));
    region.setMax(Eigen::Vector4f (30, 6.5, 1, 1));
    region.setInputCloud(cloud_filtered);
    region.filter(*cloudROI);
    

Works fine for me.

But know the next step doesn't work

  1. Now I want to filter some points around my Lidar source
  2. Therefore I create a second cropbox with the InputCloud from my first segmentation
std::vector<int> indices;
pcl::CropBox<PointT> roof(true);
roof.setMin(Eigen::Vector4f (-1.5, -1.7, -1, 1));
roof.setMax(Eigen::Vector4f (2.6, 1.7, -0.4, 1));
roof.setInputCloud(cloudROI);
region.filter(indices);

pcl::PointIndices::Ptr inliers {new pcl::PointIndices};
for (int point : indices)
{
 inliers->indices.push_back(point);
  std::cout << "Found inliers" << std::endl;
}

pcl::ExtractIndices<PointT> extract;
extract.setInputCloud(cloudROI);
extract.setIndices(inliers);
extract.setNegative(true);
extract.filter(*cloudROI);  

If I simulate my code I get the following result.

First picture is without filtering the roof points around my Lidar

Result, with second cropbox

As you can see, the filter cropped points from the plane on the right side, although my box is never that big. Also keeps the one in the middle.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

Seems like a simple bug, just replace the code from region.filter(indices) to roof.filter(indices), the other part looks good

pcl::CropBox<PointT> roof(true);
roof.setMin(Eigen::Vector4f (-1.5, -1.7, -1, 1));
roof.setMax(Eigen::Vector4f (2.6, 1.7, -0.4, 1));
roof.setInputCloud(cloudROI);
region.filter(indices); // <-------

You were having issue because the inliers is the result of region cropbox with respect to the cloud_filtered. However, you extract the negative indices of the inliers with respect to the cloudROI indices, that's why you received the point that you're not expecting

Ardiya
  • 677
  • 6
  • 19