为什么PCL条件过滤器返回相同的点云?

时间:2016-10-09 10:26:51

标签: c++ point-cloud-library point-clouds

我正在与PCL一起处理点云,以一种方式检测场景中的对象。

我添加了一个自定义PiontT类型,它对我很好。但是,我正在努力使用PCL库中的过滤算法。我尝试删除统计,半径和条件异常值以消除噪音。统计数据没有返回结果(在我看来好像它处于无限循环中),另一方面,半径返回大小为0的云。条件实际上返回相同的云而不删除任何点。在半径和统计中,我按照给出的例子,但它们不起作用。

目前,我认为条件删除对我来说是最合适的算法,因为我希望删除任何不在[0.4 - 1]范围内的点。正如我之前提到的那样,我正在使用自定义点类型。下面是Point Type(Tango3DPoitType)的代码和使用条件删除的方法。

Tango3DPoitType.h

   #define PCL_NO_PRECOMPILE
   #include <pcl/point_types.h>
   #include <pcl/impl/point_types.hpp>
   #include <pcl/point_cloud.h>
   #include <pcl/impl/instantiate.hpp>

   // Preserve API for PCL users < 1.4
   #include <pcl/common/distances.h>
   #include <pcl/io/pcd_io.h>
   #include <pcl/kdtree/kdtree_flann.h>
   #include <pcl/kdtree/impl/kdtree_flann.hpp>
   #include <pcl/search/organized.h>
   #include <pcl/search/impl/organized.hpp>
   #include <pcl/filters/statistical_outlier_removal.h>
   #include <pcl/filters/impl/statistical_outlier_removal.hpp>
   #include <pcl/filters/radius_outlier_removal.h>
   #include <pcl/filters/impl/radius_outlier_removal.hpp>
   #include <pcl/filters/voxel_grid.h>
   #include <pcl/filters/impl/voxel_grid.hpp>
   #include <pcl/filters/voxel_grid_covariance.h>
   #include <pcl/filters/impl/voxel_grid_covariance.hpp>
   #include <pcl/filters/extract_indices.h>
   #include <pcl/filters/impl/extract_indices.hpp>
   #include <pcl/filters/conditional_removal.h>
   #include <pcl/filters/impl/conditional_removal.hpp>
   #include <pcl/segmentation/sac_segmentation.h>
   #include <pcl/segmentation/impl/sac_segmentation.hpp>
   #include <pcl/segmentation/extract_clusters.h>
   #include <pcl/segmentation/impl/extract_clusters.hpp>
   #include <pcl/sample_consensus/method_types.h>
   #include <pcl/sample_consensus/model_types.h>

    struct EIGEN_ALIGN16 _Tango3DPoitType
    {
       PCL_ADD_POINT4D; // This adds the members x,y,z which can also be accessed using the point (which is float[4])

      union
      {
        union
        {
          struct
          {
            uint8_t b;
            uint8_t g;
            uint8_t r;
            uint8_t a;
          }; float rgb;
        }; uint32_t rgba;
      };
      float Confidence;
      EIGEN_MAKE_ALIGNED_OPERATOR_NEW };

    struct EIGEN_ALIGN16 Tango3DPoitType : public _Tango3DPoitType
    {
       inline Tango3DPoitType ()
       {
         x = y = z = 0.0f;
         data[3] = 1.0f;
         r = b = a = 0;
         g = 255;
         Confidence = 0.0f;
        }

       inline Tango3DPoitType (float _Confidence)
       {
         x = y = z = 0.0f;
         data[3] = 1.0f;
         r = b = a = 0;
         g = 255;
         Confidence = _Confidence;
       }

       inline Tango3DPoitType (uint8_t _r, uint8_t _g, uint8_t _b)
       {
         x = y = z = 0.0f;
         data[3] = 1.0f;
         r = _r;
         g = _g;
         b = _b;
         a = 0;
         Confidence = 0;
        }

      inline Eigen::Vector3i getRGBVector3i () { return (Eigen::Vector3i (r, g, b)); }
      inline const Eigen::Vector3i getRGBVector3i () const { return (Eigen::Vector3i (r, g, b)); }
      inline Eigen::Vector4i getRGBVector4i () { return (Eigen::Vector4i (r, g, b, 0)); }
      inline const Eigen::Vector4i getRGBVector4i () const { return (Eigen::Vector4i (r, g, b, 0)); }

      EIGEN_MAKE_ALIGNED_OPERATOR_NEW };

   // Adding confidence as fourth data to XYZ
   POINT_CLOUD_REGISTER_POINT_STRUCT (Tango3DPoitType,
                                     (float, x, x)
                                     (float, y, y)
                                     (float, z, z)
                                     (uint32_t, rgba, rgba)
                                     (float, Confidence, Confidence)
    )

   POINT_CLOUD_REGISTER_POINT_WRAPPER(Tango3DPoitType, _Tango3DPoitType)

条件删除方法

  void CloudDenoising(const pcl::PointCloud<Tango3DPoitType>::Ptr source, 
                const pcl::PointCloud<Tango3DPoitType>::Ptr target){ 

    // build the condition 
    pcl::ConditionAnd<Tango3DPoitType>::Ptr ConfidenceRangeCondition (new pcl::ConditionAnd<Tango3DPoitType> ()); 

    ConfidenceRangeCondition->addComparison (pcl::FieldComparison<Tango3DPoitType>::ConstPtr (new pcl::FieldComparison<Tango3DPoitType> ("Confidence", pcl::ComparisonOps::GT, 0.5))); 
    ConfidenceRangeCondition->addComparison (pcl::FieldComparison<Tango3DPoitType>::ConstPtr (new pcl::FieldComparison<Tango3DPoitType> ("Confidence", pcl::ComparisonOps::LT, 1.1))); 

    // build the filter 
    pcl::ConditionalRemoval<Tango3DPoitType> conditionalRemoval; 
    conditionalRemoval.setCondition (ConfidenceRangeCondition); 
    conditionalRemoval.setInputCloud (source); 
    conditionalRemoval.setKeepOrganized(true); 

    // apply filter 
    conditionalRemoval.filter (*target); 
    } 

我想明白我在点类型上做错了什么,或者它是PCL库中的错误。

谢谢

1 个答案:

答案 0 :(得分:2)

你正在裁剪云,但它仍然有组织。 要解决此问题,只需删除方法.setKeepOrganized(true)