mirror of
https://github.com/introlab/rtabmap.git
synced 2026-10-03 16:47:47 +08:00
Added RANSAC rejection filter to PCL ICP
This commit is contained in:
@@ -831,7 +831,7 @@ class RTABMAP_CORE_EXPORT Parameters
|
||||
RTABMAP_PARAM(Icp, PointToPlaneGroundNormalsUp, float, 0.0, "Invert normals on ground if they are pointing down (useful for ring-like 3D LiDARs). 0 means disabled, 1 means only normals perfectly aligned with -z axis. This is only done with 3D scans.");
|
||||
RTABMAP_PARAM(Icp, PointToPlaneMinComplexity, float, 0.02, uFormat("Minimum structural complexity (0.0=low, 1.0=high) of the scan to do PointToPlane registration, otherwise PointToPoint registration is done instead and strategy from %s is used. This check is done only when %s=true.", kIcpPointToPlaneLowComplexityStrategy().c_str(), kIcpPointToPlane().c_str()));
|
||||
RTABMAP_PARAM(Icp, PointToPlaneLowComplexityStrategy, int, 1, uFormat("If structural complexity is below %s: set to 0 to so that the transform is automatically rejected, set to 1 to limit ICP correction in axes with most constraints (e.g., for a corridor-like environment, the resulting transform will be limited in y and yaw, x will taken from the guess), set to 2 to accept \"as is\" the transform computed by PointToPoint.", kIcpPointToPlaneMinComplexity().c_str()));
|
||||
RTABMAP_PARAM(Icp, OutlierRatio, float, 0.85, uFormat("Outlier ratio used with %s>0. For libpointmatcher, this parameter set TrimmedDistOutlierFilter/ratio for convenience when configuration file is not set. For CCCoreLib, this parameter set the \"finalOverlapRatio\". The value should be between 0 and 1.", kIcpStrategy().c_str()));
|
||||
RTABMAP_PARAM(Icp, OutlierRatio, float, 0.85, uFormat("Outlier ratio. For libpointmatcher (%s=1), sets TrimmedDistOutlierFilter/ratio for convenience when configuration file is not set. For CCCoreLib (%s=2), sets \"finalOverlapRatio\". For PCL (%s=0), if 0<value<1, installs a RANSAC correspondence rejector with inlier threshold = value * %s. The value should be between 0 and 1.", kIcpStrategy().c_str(), kIcpStrategy().c_str(), kIcpStrategy().c_str(), kIcpMaxCorrespondenceDistance().c_str()));
|
||||
RTABMAP_PARAM_STR(Icp, DebugExportFormat, "", "Export scans used for ICP in the specified format (a warning on terminal will be shown with the file paths used). Supported formats are \"pcd\", \"ply\" or \"vtk\". If logger level is debug, from and to scans will stamped, so previous files won't be overwritten.");
|
||||
|
||||
// libpointmatcher
|
||||
|
||||
@@ -214,10 +214,15 @@ Transform RTABMAP_CORE_EXPORT icp(
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<pcl::PointXYZ> & cloud_source_registered,
|
||||
float epsilon = 0.0f,
|
||||
bool icp2D = false);
|
||||
bool icp2D = false,
|
||||
float ransacOutlierRatio = 0.0f);
|
||||
/**
|
||||
* @brief Performs Iterative Closest Point (ICP) alignment between two point clouds and returns the resulting transform.
|
||||
* @see util3d::icp()
|
||||
*
|
||||
* @param ransacOutlierRatio If > 0 and < 1, install a PCL RANSAC
|
||||
* correspondence rejector with inlier threshold = ransacOutlierRatio *
|
||||
* maxCorrespondenceDistance. 0 disables the rejector (default).
|
||||
*/
|
||||
Transform RTABMAP_CORE_EXPORT icp(
|
||||
const pcl::PointCloud<pcl::PointXYZI>::ConstPtr & cloud_source,
|
||||
@@ -227,7 +232,8 @@ Transform RTABMAP_CORE_EXPORT icp(
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<pcl::PointXYZI> & cloud_source_registered,
|
||||
float epsilon = 0.0f,
|
||||
bool icp2D = false);
|
||||
bool icp2D = false,
|
||||
float ransacOutlierRatio = 0.0f);
|
||||
|
||||
/**
|
||||
* @brief Performs Iterative Closest Point (ICP) alignment using a point-to-plane error metric.
|
||||
@@ -262,10 +268,15 @@ Transform RTABMAP_CORE_EXPORT icpPointToPlane(
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<pcl::PointNormal> & cloud_source_registered,
|
||||
float epsilon = 0.0f,
|
||||
bool icp2D = false);
|
||||
bool icp2D = false,
|
||||
float ransacOutlierRatio = 0.0f);
|
||||
/**
|
||||
* @briefPerforms Iterative Closest Point (ICP) alignment using a point-to-plane error metric.
|
||||
* @see util3d::icpPointToPlane()
|
||||
*
|
||||
* @param ransacOutlierRatio If > 0 and < 1, install a PCL RANSAC
|
||||
* correspondence rejector with inlier threshold = ransacOutlierRatio *
|
||||
* maxCorrespondenceDistance. 0 disables the rejector (default).
|
||||
*/
|
||||
Transform RTABMAP_CORE_EXPORT icpPointToPlane(
|
||||
const pcl::PointCloud<pcl::PointXYZINormal>::ConstPtr & cloud_source,
|
||||
@@ -275,7 +286,8 @@ Transform RTABMAP_CORE_EXPORT icpPointToPlane(
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<pcl::PointXYZINormal> & cloud_source_registered,
|
||||
float epsilon = 0.0f,
|
||||
bool icp2D = false);
|
||||
bool icp2D = false,
|
||||
float ransacOutlierRatio = 0.0f);
|
||||
|
||||
} // namespace util3d
|
||||
} // namespace rtabmap
|
||||
|
||||
@@ -644,7 +644,8 @@ Transform RegistrationIcp::computeTransformationImpl(
|
||||
hasConverged,
|
||||
*fromCloudNormalsRegistered,
|
||||
_epsilon,
|
||||
this->force3DoF());
|
||||
this->force3DoF(),
|
||||
_outlierRatio);
|
||||
}
|
||||
|
||||
if(!icpT.isNull() && hasConverged)
|
||||
@@ -778,7 +779,8 @@ Transform RegistrationIcp::computeTransformationImpl(
|
||||
hasConverged,
|
||||
*fromCloudRegistered,
|
||||
_epsilon,
|
||||
this->force3DoF()); // icp2D
|
||||
this->force3DoF(), // icp2D
|
||||
_outlierRatio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "rtabmap/core/util3d_filtering.h"
|
||||
#include "rtabmap/core/util3d.h"
|
||||
|
||||
#include <pcl/registration/correspondence_rejection_sample_consensus.h>
|
||||
#include <pcl/registration/icp.h>
|
||||
#include <pcl/registration/transformation_estimation_2D.h>
|
||||
#include <pcl/registration/transformation_estimation_svd.h>
|
||||
@@ -402,7 +403,8 @@ Transform icpImpl(const typename pcl::PointCloud<PointT>::ConstPtr & cloud_sourc
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<PointT> & cloud_source_registered,
|
||||
float epsilon,
|
||||
bool icp2D)
|
||||
bool icp2D,
|
||||
float ransacOutlierRatio)
|
||||
{
|
||||
pcl::IterativeClosestPoint<PointT, PointT> icp;
|
||||
// Set the input source and target
|
||||
@@ -416,7 +418,7 @@ Transform icpImpl(const typename pcl::PointCloud<PointT>::ConstPtr & cloud_sourc
|
||||
icp.setTransformationEstimation(est);
|
||||
}
|
||||
|
||||
// Set the max correspondence distance to 5cm (e.g., correspondences with higher distances will be ignored)
|
||||
// Set the max correspondence distance (e.g., correspondences with higher distances will be ignored)
|
||||
icp.setMaxCorrespondenceDistance (maxCorrespondenceDistance);
|
||||
// Set the maximum number of iterations (criterion 1)
|
||||
icp.setMaximumIterations (maximumIterations);
|
||||
@@ -424,7 +426,22 @@ Transform icpImpl(const typename pcl::PointCloud<PointT>::ConstPtr & cloud_sourc
|
||||
icp.setTransformationEpsilon (epsilon*epsilon);
|
||||
// Set the euclidean distance difference epsilon (criterion 3)
|
||||
//icp.setEuclideanFitnessEpsilon (-std::numeric_limits<double>::max());
|
||||
//icp.setRANSACOutlierRejectionThreshold(maxCorrespondenceDistance);
|
||||
|
||||
if(ransacOutlierRatio > 0.0f && ransacOutlierRatio < 1.0f)
|
||||
{
|
||||
// RANSAC-based correspondence rejector: fits a rigid transform on
|
||||
// random 3-pair subsets and discards pairs that disagree. Note that
|
||||
// PCL's IterativeClosestPoint::setRANSACOutlierRejectionThreshold and
|
||||
// setRANSACIterations are NOT honored by ICP itself (only by NDT and
|
||||
// k-4PCS), so we install the rejector explicitly.
|
||||
typename pcl::registration::CorrespondenceRejectorSampleConsensus<PointT>::Ptr
|
||||
ransacRejector(new pcl::registration::CorrespondenceRejectorSampleConsensus<PointT>());
|
||||
ransacRejector->setInlierThreshold(maxCorrespondenceDistance * ransacOutlierRatio);
|
||||
ransacRejector->setMaximumIterations(50);
|
||||
ransacRejector->setInputSource(cloud_source);
|
||||
ransacRejector->setInputTarget(cloud_target);
|
||||
icp.addCorrespondenceRejector(ransacRejector);
|
||||
}
|
||||
|
||||
// Perform the alignment
|
||||
icp.align (cloud_source_registered);
|
||||
@@ -440,9 +457,10 @@ Transform icp(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr & cloud_source,
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<pcl::PointXYZ> & cloud_source_registered,
|
||||
float epsilon,
|
||||
bool icp2D)
|
||||
bool icp2D,
|
||||
float ransacOutlierRatio)
|
||||
{
|
||||
return icpImpl(cloud_source, cloud_target, maxCorrespondenceDistance, maximumIterations, hasConverged, cloud_source_registered, epsilon, icp2D);
|
||||
return icpImpl(cloud_source, cloud_target, maxCorrespondenceDistance, maximumIterations, hasConverged, cloud_source_registered, epsilon, icp2D, ransacOutlierRatio);
|
||||
}
|
||||
|
||||
// return transform from source to target (All points must be finite!!!)
|
||||
@@ -453,9 +471,10 @@ Transform icp(const pcl::PointCloud<pcl::PointXYZI>::ConstPtr & cloud_source,
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<pcl::PointXYZI> & cloud_source_registered,
|
||||
float epsilon,
|
||||
bool icp2D)
|
||||
bool icp2D,
|
||||
float ransacOutlierRatio)
|
||||
{
|
||||
return icpImpl(cloud_source, cloud_target, maxCorrespondenceDistance, maximumIterations, hasConverged, cloud_source_registered, epsilon, icp2D);
|
||||
return icpImpl(cloud_source, cloud_target, maxCorrespondenceDistance, maximumIterations, hasConverged, cloud_source_registered, epsilon, icp2D, ransacOutlierRatio);
|
||||
}
|
||||
|
||||
// return transform from source to target (All points/normals must be finite!!!)
|
||||
@@ -468,7 +487,8 @@ Transform icpPointToPlaneImpl(
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<PointNormalT> & cloud_source_registered,
|
||||
float epsilon,
|
||||
bool icp2D)
|
||||
bool icp2D,
|
||||
float ransacOutlierRatio)
|
||||
{
|
||||
pcl::IterativeClosestPoint<PointNormalT, PointNormalT> icp;
|
||||
// Set the input source and target
|
||||
@@ -479,7 +499,7 @@ Transform icpPointToPlaneImpl(
|
||||
est.reset(new pcl::registration::TransformationEstimationPointToPlaneLLS<PointNormalT, PointNormalT>);
|
||||
icp.setTransformationEstimation(est);
|
||||
|
||||
// Set the max correspondence distance to 5cm (e.g., correspondences with higher distances will be ignored)
|
||||
// Set the max correspondence distance (e.g., correspondences with higher distances will be ignored)
|
||||
icp.setMaxCorrespondenceDistance (maxCorrespondenceDistance);
|
||||
// Set the maximum number of iterations (criterion 1)
|
||||
icp.setMaximumIterations (maximumIterations);
|
||||
@@ -487,7 +507,19 @@ Transform icpPointToPlaneImpl(
|
||||
icp.setTransformationEpsilon (epsilon*epsilon);
|
||||
// Set the euclidean distance difference epsilon (criterion 3)
|
||||
//icp.setEuclideanFitnessEpsilon (1);
|
||||
//icp.setRANSACOutlierRejectionThreshold(maxCorrespondenceDistance);
|
||||
|
||||
if(ransacOutlierRatio > 0.0f && ransacOutlierRatio < 1.0f)
|
||||
{
|
||||
// See icpImpl: install a RANSAC correspondence rejector since PCL's
|
||||
// setRANSAC*-on-ICP is a no-op.
|
||||
typename pcl::registration::CorrespondenceRejectorSampleConsensus<PointNormalT>::Ptr
|
||||
ransacRejector(new pcl::registration::CorrespondenceRejectorSampleConsensus<PointNormalT>());
|
||||
ransacRejector->setInlierThreshold(maxCorrespondenceDistance * ransacOutlierRatio);
|
||||
ransacRejector->setMaximumIterations(50);
|
||||
ransacRejector->setInputSource(cloud_source);
|
||||
ransacRejector->setInputTarget(cloud_target);
|
||||
icp.addCorrespondenceRejector(ransacRejector);
|
||||
}
|
||||
|
||||
// Perform the alignment
|
||||
icp.align (cloud_source_registered);
|
||||
@@ -513,9 +545,10 @@ Transform icpPointToPlane(
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<pcl::PointNormal> & cloud_source_registered,
|
||||
float epsilon,
|
||||
bool icp2D)
|
||||
bool icp2D,
|
||||
float ransacOutlierRatio)
|
||||
{
|
||||
return icpPointToPlaneImpl(cloud_source, cloud_target, maxCorrespondenceDistance, maximumIterations, hasConverged, cloud_source_registered, epsilon, icp2D);
|
||||
return icpPointToPlaneImpl(cloud_source, cloud_target, maxCorrespondenceDistance, maximumIterations, hasConverged, cloud_source_registered, epsilon, icp2D, ransacOutlierRatio);
|
||||
}
|
||||
// return transform from source to target (All points/normals must be finite!!!)
|
||||
Transform icpPointToPlane(
|
||||
@@ -526,9 +559,10 @@ Transform icpPointToPlane(
|
||||
bool & hasConverged,
|
||||
pcl::PointCloud<pcl::PointXYZINormal> & cloud_source_registered,
|
||||
float epsilon,
|
||||
bool icp2D)
|
||||
bool icp2D,
|
||||
float ransacOutlierRatio)
|
||||
{
|
||||
return icpPointToPlaneImpl(cloud_source, cloud_target, maxCorrespondenceDistance, maximumIterations, hasConverged, cloud_source_registered, epsilon, icp2D);
|
||||
return icpPointToPlaneImpl(cloud_source, cloud_target, maxCorrespondenceDistance, maximumIterations, hasConverged, cloud_source_registered, epsilon, icp2D, ransacOutlierRatio);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -448,10 +448,6 @@ class RtabmapIntegrationFixture : public ::testing::Test {};
|
||||
// ---------------------------------------------------------------------------
|
||||
TEST_F(RtabmapIntegrationFixture, NetherdroneLidar3D)
|
||||
{
|
||||
#ifndef RTABMAP_POINTMATCHER
|
||||
GTEST_SKIP() << "Sparse 3D lidar ICP needs libpointmatcher; the PCL "
|
||||
"fallback diverges on this dataset.";
|
||||
#endif
|
||||
const std::string dbPath = testDataPath("netherdrone_lidar3d_sample_15s.db");
|
||||
SKIP_IF_MISSING(dbPath);
|
||||
|
||||
@@ -474,7 +470,15 @@ TEST_F(RtabmapIntegrationFixture, NetherdroneLidar3D)
|
||||
rtabmapParams[Parameters::kIcpIterations()] = "10";
|
||||
rtabmapParams[Parameters::kIcpMaxCorrespondenceDistance()] = uNumber2Str(voxelSize * 10.0f);
|
||||
rtabmapParams[Parameters::kIcpMaxTranslation()] = "3";
|
||||
// OutlierRatio means different things per ICP backend (see Parameters.h):
|
||||
// libpointmatcher uses it as TrimmedDist keep-ratio (mild trim at 0.7);
|
||||
// PCL uses it as a RANSAC threshold multiplier on maxCorrespondenceDistance,
|
||||
// where 0.1 gives the aggressive filtering this sparse lidar needs.
|
||||
#ifdef RTABMAP_POINTMATCHER
|
||||
rtabmapParams[Parameters::kIcpOutlierRatio()] = "0.7";
|
||||
#else
|
||||
rtabmapParams[Parameters::kIcpOutlierRatio()] = "0.1";
|
||||
#endif
|
||||
rtabmapParams[Parameters::kIcpPointToPlane()] = "true";
|
||||
rtabmapParams[Parameters::kIcpPointToPlaneK()] = "20";
|
||||
rtabmapParams[Parameters::kIcpPointToPlaneRadius()] = "0";
|
||||
@@ -554,12 +558,19 @@ TEST_F(RtabmapIntegrationFixture, NetherdroneLidar3D)
|
||||
EXPECT_NEAR(1845, result.octomapObstacleCells, 50);
|
||||
#endif
|
||||
|
||||
// Replay is deterministic; matching golden GT was captured from a clean
|
||||
// run of this exact configuration, so RMSE should be ~0.
|
||||
// libpointmatcher's TrimmedDist outlier filter aligns this sparse 3D-lidar
|
||||
// dataset to sub-mm RMSE against the golden trajectory. With PCL ICP the
|
||||
// best we can do is a RANSAC correspondence rejector (see
|
||||
// util3d_registration.cpp), which converges but to a looser ~3 cm RMSE.
|
||||
ASSERT_GE(result.translationalRmseFinal, 0.0f)
|
||||
<< "No Gt/translational_rmse in stats (golden GT not injected?)";
|
||||
#ifdef RTABMAP_POINTMATCHER
|
||||
EXPECT_LT(result.translationalRmseFinal, 0.001f)
|
||||
<< "Final trajectory RMSE = " << result.translationalRmseFinal << " m";
|
||||
#else
|
||||
EXPECT_LT(result.translationalRmseFinal, 0.05f)
|
||||
<< "Final trajectory RMSE = " << result.translationalRmseFinal << " m";
|
||||
#endif
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -672,7 +683,12 @@ TEST_F(RtabmapIntegrationFixture, PR2_Scan2D_RGBD_IcpReg)
|
||||
rtabmapParams[Parameters::kIcpCorrespondenceRatio()] = "0.10";
|
||||
rtabmapParams[Parameters::kIcpEpsilon()] = "0.001";
|
||||
rtabmapParams[Parameters::kIcpMaxTranslation()] = "0.5";
|
||||
// See Netherdrone test comment: OutlierRatio is backend-dependent.
|
||||
#ifdef RTABMAP_POINTMATCHER
|
||||
rtabmapParams[Parameters::kIcpOutlierRatio()] = "0.95";
|
||||
#else
|
||||
rtabmapParams[Parameters::kIcpOutlierRatio()] = "0.85";
|
||||
#endif
|
||||
rtabmapParams[Parameters::kIcpPointToPlane()] = "true";
|
||||
rtabmapParams[Parameters::kIcpVoxelSize()] = "0.0";
|
||||
rtabmapParams[Parameters::kMemBinDataKept()] = "true";
|
||||
@@ -700,11 +716,13 @@ TEST_F(RtabmapIntegrationFixture, PR2_Scan2D_RGBD_IcpReg)
|
||||
EXPECT_EQ(21, result.finalGlobalGraphSize);
|
||||
EXPECT_GE(result.proximityDetections, 1)
|
||||
<< "PR2 2D-scan dataset should produce proximity detections";
|
||||
// Observed: empty 22785-23106, obstacle 1302-1410.
|
||||
// Observed: empty 22785-23455, obstacle 1302-1580. Range widened to
|
||||
// absorb run-to-run variance from the RANSAC correspondence rejector
|
||||
// installed in the PCL ICP path (util3d_registration.cpp).
|
||||
EXPECT_GE(result.gridEmptyCells, 22500);
|
||||
EXPECT_LE(result.gridEmptyCells, 23200);
|
||||
EXPECT_LE(result.gridEmptyCells, 23800);
|
||||
EXPECT_GE(result.gridObstacleCells, 1250);
|
||||
EXPECT_LE(result.gridObstacleCells, 1450);
|
||||
EXPECT_LE(result.gridObstacleCells, 1700);
|
||||
#ifdef RTABMAP_OCTOMAP
|
||||
// 2D-laser-only signatures: nothing to assemble into a 3D OctoMap.
|
||||
EXPECT_EQ(0, result.octomapEmptyCells);
|
||||
|
||||
Reference in New Issue
Block a user