Search code examples
point-cloud-librarypoint-clouds

PCL Color Filter


I want to filter out the points in a point cloud with a certain 'r' value.

I looked at the documentation, and noticed pcl/filters/color.h is no longer available in PCL 1.7 and above, which is puzzling. (http://docs.pointclouds.org/1.3.1/classpcl_1_1_color_filter.html).

I can probably do this with a naive for loop, but was wondering if there is a way using the pass-through filter conditions, as that is probably multithreaded.


Solution

  • I ended up using conditional_removal, there is a template specialization for RGB. Here is a snippet where we get a ROS point cloud called cloud_msg.

     #include <pcl/filters/conditional_removal.h> //and the other usuals
    
     pcl::PointCloud<pcl::PointXYZRGB>::Ptr rgb_cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
     pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZRGB>);
     pcl::fromROSMsg(*cloud_msg, *rgb_cloud);
     pcl::PCLPointCloud2 cloud_filtered_ros;
    
     pcl::ConditionalRemoval<pcl::PointXYZRGB> color_filter;
    
     pcl::PackedRGBComparison<pcl::PointXYZRGB>::Ptr
         red_condition(new pcl::PackedRGBComparison<pcl::PointXYZRGB>("r", pcl::ComparisonOps::GT, 90));
     pcl::ConditionAnd<pcl::PointXYZRGB>::Ptr color_cond (new pcl::ConditionAnd<pcl::PointXYZRGB> ());
     color_cond->addComparison (red_condition);
    
     // Build the filter
     color_filter.setInputCloud(rgb_cloud);
     color_filter.setCondition (color_cond);
     color_filter.filter(*cloud_filtered)