问题
I'm new in PCL. I'm using the PCL library and I'm looking for a way to extract points from a point cloud or copying particular points to a new one. I want to verify for each point if it respects a condition and I want to obtain a point cloud with only the good points.Thank you!
回答1:
Use the ExtractIndices class:
- add your points to be removed to a PointIndices variable
- pass these Indices to the ExtractIndices
- run filter() method "negatively" to get the original cloud minus your points
example:
pcl::PointCloud<pcl::PointXYZ>::Ptr p_obstacles(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointIndices::Ptr inliers(new pcl::PointIndices());
pcl::ExtractIndices<pcl::PointXYZ> extract;
for (int i = 0; i < (*p_obstacles).size(); i++)
{
pcl::PointXYZ pt(p_obstacles->points[i].x, p_obstacles->points[i].y, p_obstacles->points[i].z);
float zAvg = 0.5f;
if (abs(pt.z - zAvg) < THRESHOLD) // e.g. remove all pts below zAvg
{
inliers->indices.push_back(i);
}
}
extract.setInputCloud(p_obstacles);
extract.setIndices(inliers);
extract.setNegative(true);
extract.filter(*p_obstacles);
回答2:
If you are new to PCL. It should be a good idea to take a look at at the documentation:
http://pointclouds.org/documentation/tutorials/
I think that what you are looking for is explained in this tutorial:
http://pointclouds.org/documentation/tutorials/remove_outliers.php#remove-outliers
Try to reproduce the example on your machine and then modify it to fit your needs.
来源:https://stackoverflow.com/questions/44921987/removing-points-from-a-pclpointcloudpclpointxyzrgb