I am working with PCL to process a point cloud to finish detecting objects in a scene.
I am adding a custom type of PiontT and it works fine with me. However, I struggle with filtering algorithms in the PCL library. I tried to remove the statistical, radius and conditional outliers in order to remove the noise. The statistics did not return results (it seems to me in an infinite loop), the radius, on the other hand, returns a cloud with a size of 0. And the conditional actually returns the same cloud without deleting a single point. both in radius and in statistical, I follow the given example, but they do not work.
At present, I believe that conditional deletion is the most correct algorithm for me, because I want to delete all points with confidence, not in the range between [0.4 - 1]. As I said, I use a custom point type. Below is the code for the type "Type" (Tango3DPoitType) and a method that uses conditional deletion.
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>
#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;
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 };
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)
Conditional delete method
void CloudDenoising(const pcl::PointCloud<Tango3DPoitType>::Ptr source,
const pcl::PointCloud<Tango3DPoitType>::Ptr target){
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)));
pcl::ConditionalRemoval<Tango3DPoitType> conditionalRemoval;
conditionalRemoval.setCondition (ConfidenceRangeCondition);
conditionalRemoval.setInputCloud (source);
conditionalRemoval.setKeepOrganized(true);
conditionalRemoval.filter (*target);
}
I want to understand that I am doing something wrong with the point type or is it a mistake in the PCL library.
thank