Reputation: 339
I'm working with PCL to process a point cloud in a way to end with detecting objects in the scene.
I add a custom PiontT type and it work fine with me. However, I'm struggling with the filtering algorithms in the PCL library. I tried statistical, radius, and conditional outliers removal to remove noise. The statistical did not return the results (it seems to me as if it in an infinite loop), the radius on the other hand return a cloud with size 0. and the conditional actually return the same cloud without removing any point. in both radius and statistical, I follow the example as it given but they did not work.
For now, I think the conditional removal is the most proper algorithm for me, because I want to remove any points with confidence not in the range between [0.4 - 1] . As I mentioned before that I'm using a custom point type. below is the code for the point Type (Tango3DPoitType) and the method that use conditional removal.
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)
Conditional Removal Method
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);
}
I want to understand is I'm doing something wrong with the point type or is it a bug in PCL library.
Thank you
Upvotes: 5
Views: 1301
Reputation: 31
You are cropping the cloud but it still leting organized.
To solve it, just remove the method .setKeepOrganized(true)
.
Upvotes: 3