mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-03 01:50:24 +08:00
* added doc and tests for util2d.h * updated cmake-ros ci * Added util3d.h doc and tests * util3d_transforms.h: Added doc and tests * util3d_filtering.h: started doc and test * util3d_filtering.h: more tests and doc * Added more doc/tests * finished util3d_filtering doc and tests * added test for util2d::depthBleedingFiltering * Added util3d_registration tests * Added util3d_features.h doc/tests * added doc/tests for util3d_correspondences.h * added doc/gtest for util3d_mapping.h (missing hpp functions) * finished testing util3d_mapping.hpp * Added util3d_motion_estimation.h tests (2D->3D done) * finished util3d_motion_estimation.h tests * minimal util3d_surface.h * Added Transform and VisualWord tests * Added doc for CameraModel and StereoCameraModel * Added more logs in ros ci * Passing tests on fical * improved all devcontainer * added devcontainer kilted, fixed source setup.bash, removed ldconfig in ros-cmake workflow * cleanup * source ros * Added utilite tests * Added testing to appveyor, github actions cancellable on re-commit on same branch * appveyor testing without all targets * appveyor: specifying ALL_BUILD target * Fixed Util2dTest.NMSImageBoundsRespected test * Fixing PCL Indices error on old pcl * Added VWDictionary tests and doc. Fixed LSH not working (fix from https://github.com/flann-lib/flann/pull/472 * fixing some appveyor CI errors, added test to check dictionary serialization against all type * Added StereoDense, StereoBM and StereoSGBM doc and tests * Added Stereo tests * Added CameraModel and StereoCameraModel tests * Added doc and test for Statistics * Added doc/tests for Signature * Added doc/test for SensorEvent, added doc for SensorCaptureInfo * Added doc to SensorData * Added SensorData tests * Added SensorCapture and SensorCaptureThread doc and tests * fixed sensordata test * updated SSC test and doc * Added doc and tests for BayesFilter class * Enabled testing on mac, updated windows testing like on linux * added test_link * fixed unresolved on windows * fixed ThreadHandle error on macos ci * Added GPS and GeodeticCoords tests * Added tests for compression * Added Odometry tests (base class only) * Added DBDriver tests * Added coverage report * uniformized test names * fixing concurancy and coverage ci * dont built tools, examples and app for coverage build * fixed report tool rebuilt without qt compilation error * updated coverage option * updated coverage config * added doc CI job * fixing windows and mac ci errors * Added DBDriverSqlite3 tests * Added IMU tests * Added Graph tests * fixing flaky macos test * Added IMUThread and IMUFilter tests * Added Landmarks tests * Added LASWriter tests * fixing seed flaky test * fixing flaky macos timing tests * Added LocalGrid tests * Added LocalGridMaker tests * fixing ci errors * Added GlobalMap tests * Added doc for EnvSensor * Added Features2D tests * Added Registration tests * Added RegistrationVis tests * Added doc for Rtabmap and Memory classes * Added Memory and Rtabmap tests * making some tests less flaky * lcov 1.14 support * updated compatible tool arguments * Added integration tests (RGB-D, Stereo, Lidar2d, Lidar3d) * More octomap checks * Refactored how/when python interpretor is created to simplify library usage * Added python tests * fixed some flaky tests * suppressed some third party related warnings * fixed ceres tests * more flaky fixes * Fixing tests without libpointmatcher * Added RANSAC rejection filter to PCL ICP * fixing multi platform flakiness * Added test to detect regression * Fixing windows pcl link error * fixed some macos flakiness * bigger 2D2D registration error on opencv 4.6.0 * flakiness * fixing flaky tests on windows and mac * flaky thread test on slow mac VM * windows slow test * fixing more ci erros * fxing temp dir on windows * Added Optimizer tests and discovered some bugs (fixed) * fixing flaky tests in mac and windows * Added Optimizer doc * Added GTSAM BA, updated Ceres to use g2o ba parameters. Renamed g2o's ba related parameters to Optimizer group and used by both gtsam and ceres. * fixing build without gtsam * fixing home dir * fixing python ci isssues * Added multicam ba tests * Added Ceres multicam BA support * Aligned BundleAdjustment parameters with Optimizer/Strategy to avoid confusion in the code * Added BA integration test * Added robust graph optimization integration test * Added loop3it test * Added stereo20Hz test * Added smartfactor gtsam * Fixed bugged check and warn if python didn't return any descriptors * Fixing gtsam version build issues * fixing tilt on windows ci * loosing ceres integration test for ci * mac ci flakiness * updating missing param in gui * updating test bound for mac * added appearance-based tests, set min gftt quality to quality level * testing more stuff * improving features2d tests * ci flakiness * fixing flaky ci * ci fixes * flaky fixes * Added RegistrationIcp tests * Added icp integration test with real-worl corridor like env * intermediate nodes * fixing enum * Updated test to catch #1714 * Fixed 2d corridor failing on pcl * flaky pnp test * flaky brisk test * Set rtabmap_integration test as long * updating loop closure test * flaky ci tests * TEsting roundtrip g2o/toro save/load * loosing test bound * fixed cuda capable checks * flaky tests * Debugging test hanging * more debugging stuff * updating limit * windows: disabled cuda on ci to avoid incompatible driver issue. Fixing a bad test mem allocation * trying fixing cuda hanging issue * fixing ci flakyness * flaky tests * Updated BOW flaky tests by checking min precision/recall instead of recall@100precision. Fixed signature test * CameraModel::load() test initRectificationMap param * test dbdriver load dictionary idsOnly * Memory: test keepLinkedInDb param * added dummyDictionary tests * test intermediate nodes count * Added MarkerDetector tests * reverted breaking change of UMutex and USemaphore * Features2d: fixed compiltion warnings with clang about override * clang warnings * fixing test build with pcl 1.8 * g2o and gtsam build errors on android * opencv5 test fixes * disabled testing for ios and android builds * normalized endline characters for easier diff * added LF CRLF rule * bump 0.23.10. fixing doc version * Publish rtabmap website doc from ci * fixing MSCVC build error * macos icp flaky test * fixing ceres macos test bound * ficing more flaky tests * fixing opencv5 related test errors. Also fixed an actual bug in ENU_WGS84ToGeocentric_WGS84() * added comment about mrpt change * removed rosdoc2 (will add it for rtabmap_ros later) * fixing website style * updated download links * locally deployable website with api * sweep doxygen issues * improved/revised doxygen main pages * removed examples empty page * Updated doxygen style * more concise doxygen groups * added api link on main readme * fixing utilite test error * fixing CommonFilteringGroundNormalsUp test * updated precisionRecall test bounds for Freak and brief descriptors * fixing scale check in ba tests * disabled tests on windows cuda build (missing dlls amd runner cannot test cuda anyway) * ceres: missing suitesparse dep in windows ci * adjusting recall thr for fast/freak * ficing more flaky tests * fixing flaky tests * disabled coverage in ros ci * Enable integration tests for ros ci jobs * loosing up some threshold for failing tests * trigger cache * fixing test data in ros ci. Updated flaky test for mac * slaking some test limit * Fixed rtabmap-detectMoreLoopClosures inverted output value * loosing up sift recall on mac * optimizer re-ordered distribution for reproducible results (mac g2o) * macos dump test crash log * combining all tests to save time on shared library reload. Also fixed Logs with missing arguments. * Added ENABLE_FORMAT_ERRORS cmake option * do test only one time * fixed all format warnings * format security android build errors * less verbose tests * updated ImuUThread test * fixed a log * Fixed libpointmatcher 2d normals eigen issue * Fixing libpointmatcher conversion issues * fixing libpointmatcher test on windows ci * cleanup comments, relax some test thr * disabled sequoia-intel ci build (too flaky, would need extensive testing directly on that machine)
439 lines
14 KiB
C++
439 lines
14 KiB
C++
#include "gtest/gtest.h"
|
|
#include "rtabmap/core/util3d_registration.h"
|
|
#include "rtabmap/core/util3d_transforms.h"
|
|
#include "rtabmap/core/util3d_surface.h"
|
|
#include "rtabmap/utilite/UException.h"
|
|
#include <pcl/common/impl/angles.hpp>
|
|
#include <pcl/common/io.h>
|
|
#include <pcl/io/pcd_io.h>
|
|
|
|
using namespace rtabmap;
|
|
|
|
TEST(Util3dRegistrationTest, TransformFromXYZCorrespondencesSVDIdentityTransform)
|
|
{
|
|
pcl::PointCloud<pcl::PointXYZ> cloud1, cloud2;
|
|
cloud1.push_back(pcl::PointXYZ(1, 2, 3));
|
|
cloud1.push_back(pcl::PointXYZ(4, 5, 6));
|
|
cloud1.push_back(pcl::PointXYZ(7, 8, 9));
|
|
cloud1.push_back(pcl::PointXYZ(10, 11, 12));
|
|
cloud1.push_back(pcl::PointXYZ(1, 6, 12));
|
|
cloud2 = cloud1; // Exact same points
|
|
|
|
Transform result = util3d::transformFromXYZCorrespondencesSVD(cloud1, cloud2);
|
|
Transform identity = Transform::getIdentity();
|
|
|
|
EXPECT_LT(result.getDistance(identity), 0.001f);
|
|
EXPECT_LT(result.getAngle(identity), 0.001f);
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, TransformFromXYZCorrespondencesSVDTranslationOnly)
|
|
{
|
|
pcl::PointCloud<pcl::PointXYZ> cloud1, cloud2;
|
|
cloud1.push_back(pcl::PointXYZ(0, 0, 0));
|
|
cloud1.push_back(pcl::PointXYZ(1, 0, 0));
|
|
cloud1.push_back(pcl::PointXYZ(0, 1, 0));
|
|
|
|
cloud2.push_back(pcl::PointXYZ(1, 2, 3));
|
|
cloud2.push_back(pcl::PointXYZ(2, 2, 3));
|
|
cloud2.push_back(pcl::PointXYZ(1, 3, 3));
|
|
|
|
Transform result = util3d::transformFromXYZCorrespondencesSVD(cloud1, cloud2);
|
|
|
|
EXPECT_LT(result.getAngle(Transform::getIdentity()), 0.001f);
|
|
EXPECT_NEAR(result.x(), 1.0f, 1e-4f);
|
|
EXPECT_NEAR(result.y(), 2.0f, 1e-4f);
|
|
EXPECT_NEAR(result.z(), 3.0f, 1e-4f);
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, TransformFromXYZCorrespondencesSVDRotationAndTranslation)
|
|
{
|
|
pcl::PointCloud<pcl::PointXYZ> cloud1, cloud2;
|
|
|
|
// Original triangle
|
|
cloud1.push_back(pcl::PointXYZ(1, 0, 0));
|
|
cloud1.push_back(pcl::PointXYZ(0, 1, 0));
|
|
cloud1.push_back(pcl::PointXYZ(0, 0, 1));
|
|
|
|
// Apply known rotation (90° about Z) and translation (1, 2, 3)
|
|
Eigen::Matrix3f R;
|
|
R = Eigen::AngleAxisf(M_PI_2, Eigen::Vector3f::UnitZ());
|
|
Eigen::Vector3f t(1, 2, 3);
|
|
|
|
for (const auto & pt : cloud1.points)
|
|
{
|
|
Eigen::Vector3f p(pt.x, pt.y, pt.z);
|
|
p = R * p + t;
|
|
cloud2.push_back(pcl::PointXYZ(p[0], p[1], p[2]));
|
|
}
|
|
|
|
Transform result = util3d::transformFromXYZCorrespondencesSVD(cloud1, cloud2);
|
|
|
|
Eigen::Matrix4f expected = Eigen::Matrix4f::Identity();
|
|
expected.block<3,3>(0,0) = R;
|
|
expected.block<3,1>(0,3) = t;
|
|
Transform expected_t = Transform::fromEigen4f(expected);
|
|
|
|
EXPECT_LT(result.getAngle(expected_t), 0.001f);
|
|
EXPECT_NEAR(result.x(), expected_t.x(), 1e-4f);
|
|
EXPECT_NEAR(result.y(), expected_t.y(), 1e-4f);
|
|
EXPECT_NEAR(result.z(), expected_t.z(), 1e-4f);
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, TransformFromXYZCorrespondencesSVDMismatchedSizes)
|
|
{
|
|
pcl::PointCloud<pcl::PointXYZ> cloud1, cloud2;
|
|
cloud1.push_back(pcl::PointXYZ(0, 0, 0));
|
|
cloud1.push_back(pcl::PointXYZ(1, 1, 1));
|
|
cloud2.push_back(pcl::PointXYZ(0, 0, 0)); // Only 1 point
|
|
|
|
EXPECT_THROW(util3d::transformFromXYZCorrespondencesSVD(cloud1, cloud2), UException);
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, TransformFromXYZCorrespondencesIdentityTransform)
|
|
{
|
|
auto cloud1 = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
cloud1->push_back(pcl::PointXYZ(1, 0, 0));
|
|
cloud1->push_back(pcl::PointXYZ(0, 1, 0));
|
|
cloud1->push_back(pcl::PointXYZ(0, 0, 1));
|
|
|
|
auto cloud2 = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
*cloud2 = *cloud1;
|
|
|
|
std::vector<int> inliers;
|
|
cv::Mat covariance;
|
|
|
|
Transform result = util3d::transformFromXYZCorrespondences(
|
|
cloud1, cloud2, 0.01, 100, 0, 1.0, &inliers, &covariance);
|
|
|
|
Transform identity = Transform::getIdentity();
|
|
EXPECT_LT(result.getDistance(identity), 0.001f);
|
|
EXPECT_LT(result.getAngle(identity), 0.001f);
|
|
EXPECT_EQ(inliers.size(), 3);
|
|
EXPECT_EQ(covariance.rows, 6);
|
|
EXPECT_EQ(covariance.cols, 6);
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, TransformFromXYZCorrespondencesTranslatedCloud)
|
|
{
|
|
auto cloud1 = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
auto cloud2 = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
Eigen::Vector3f t(1.0f, 2.0f, 3.0f);
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
pcl::PointXYZ p(i, i % 2, i % 3);
|
|
cloud1->push_back(p);
|
|
cloud2->push_back(pcl::PointXYZ(p.x + t.x(), p.y + t.y(), p.z + t.z()));
|
|
}
|
|
|
|
std::vector<int> inliers;
|
|
cv::Mat covariance;
|
|
|
|
Transform result = util3d::transformFromXYZCorrespondences(
|
|
cloud1, cloud2, 0.1, 100, 0, 1.0, &inliers, &covariance);
|
|
|
|
EXPECT_LT(result.getAngle(Transform::getIdentity()), 0.001f);
|
|
EXPECT_NEAR(result.x(), t.x(), 1e-4f);
|
|
EXPECT_NEAR(result.y(), t.y(), 1e-4f);
|
|
EXPECT_NEAR(result.z(), t.z(), 1e-4f);
|
|
EXPECT_EQ(inliers.size(), 10);
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, TransformFromXYZCorrespondencesTooFewPoints)
|
|
{
|
|
auto cloud1 = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
auto cloud2 = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
|
|
cloud1->push_back(pcl::PointXYZ(0, 0, 0));
|
|
cloud2->push_back(pcl::PointXYZ(1, 1, 1));
|
|
|
|
Transform result = util3d::transformFromXYZCorrespondences(
|
|
cloud1, cloud2, 0.1, 100, 0, 1.0, nullptr, nullptr);
|
|
|
|
EXPECT_TRUE(result.isNull());
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, TransformFromXYZCorrespondencesMismatchedPointCounts)
|
|
{
|
|
auto cloud1 = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
auto cloud2 = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
|
|
cloud1->push_back(pcl::PointXYZ(0, 0, 0));
|
|
cloud1->push_back(pcl::PointXYZ(1, 0, 0));
|
|
cloud1->push_back(pcl::PointXYZ(0, 1, 0));
|
|
|
|
cloud2->push_back(pcl::PointXYZ(0, 0, 0)); // Only one point
|
|
|
|
Transform result = util3d::transformFromXYZCorrespondences(
|
|
cloud1, cloud2, 0.1, 100, 0, 1.0, nullptr, nullptr);
|
|
|
|
EXPECT_TRUE(result.isNull());
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, ComputeVarianceAndCorrespondencesPerfectMatchNoAngleCheck)
|
|
{
|
|
auto cloud1 = pcl::PointCloud<pcl::PointNormal>::Ptr(new pcl::PointCloud<pcl::PointNormal>());
|
|
auto cloud2 = pcl::PointCloud<pcl::PointNormal>::Ptr(new pcl::PointCloud<pcl::PointNormal>());
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
{
|
|
pcl::PointNormal pt;
|
|
pt.x = i; pt.y = i; pt.z = i;
|
|
pt.normal_x = 1; pt.normal_y = 0; pt.normal_z = 0;
|
|
cloud1->push_back(pt);
|
|
cloud2->push_back(pt); // identical
|
|
}
|
|
|
|
double variance = -1.0;
|
|
int correspondences = -1;
|
|
util3d::computeVarianceAndCorrespondences(
|
|
cloud1, cloud2, 0.1, -1.0, variance, correspondences, true);
|
|
|
|
EXPECT_EQ(correspondences, 5);
|
|
EXPECT_DOUBLE_EQ(variance, 0.0);
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, ComputeVarianceAndCorrespondencesNormalMismatchFilteredByAngle)
|
|
{
|
|
auto cloud1 = pcl::PointCloud<pcl::PointNormal>::Ptr(new pcl::PointCloud<pcl::PointNormal>());
|
|
auto cloud2 = pcl::PointCloud<pcl::PointNormal>::Ptr(new pcl::PointCloud<pcl::PointNormal>());
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
{
|
|
pcl::PointNormal a, b;
|
|
a.x = b.x = i; a.y = b.y = i; a.z = b.z = i;
|
|
|
|
a.normal_x = 1; a.normal_y = 0; a.normal_z = 0;
|
|
b.normal_x = 0; b.normal_y = 1; b.normal_z = 0; // orthogonal normals
|
|
|
|
cloud1->push_back(a);
|
|
cloud2->push_back(b);
|
|
}
|
|
|
|
double variance = -1.0;
|
|
int correspondences = -1;
|
|
|
|
util3d::computeVarianceAndCorrespondences(
|
|
cloud1, cloud2, 0.1, pcl::deg2rad(45.0), variance, correspondences, true);
|
|
|
|
EXPECT_EQ(correspondences, 0);
|
|
EXPECT_DOUBLE_EQ(variance, 1.0); // untouched default value
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, ComputeVarianceAndCorrespondencesAnglePassWithLargeThreshold)
|
|
{
|
|
auto cloud1 = pcl::PointCloud<pcl::PointNormal>::Ptr(new pcl::PointCloud<pcl::PointNormal>());
|
|
auto cloud2 = pcl::PointCloud<pcl::PointNormal>::Ptr(new pcl::PointCloud<pcl::PointNormal>());
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
{
|
|
pcl::PointNormal a, b;
|
|
a.x = b.x = i; a.y = b.y = i; a.z = b.z = i;
|
|
|
|
a.normal_x = 1; a.normal_y = 0; a.normal_z = 0;
|
|
b.normal_x = 0.7f; b.normal_y = 0.7f; b.normal_z = 0;
|
|
|
|
cloud1->push_back(a);
|
|
cloud2->push_back(b);
|
|
}
|
|
|
|
double variance = -1.0;
|
|
int correspondences = -1;
|
|
|
|
util3d::computeVarianceAndCorrespondences(
|
|
cloud1, cloud2, 0.1, pcl::deg2rad(90.0), variance, correspondences, true);
|
|
|
|
EXPECT_EQ(correspondences, 5);
|
|
EXPECT_GE(variance, 0.0);
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, ComputeVarianceAndCorrespondencesNoCorrespondencesDueToDistance)
|
|
{
|
|
auto cloud1 = pcl::PointCloud<pcl::PointNormal>::Ptr(new pcl::PointCloud<pcl::PointNormal>());
|
|
auto cloud2 = pcl::PointCloud<pcl::PointNormal>::Ptr(new pcl::PointCloud<pcl::PointNormal>());
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
{
|
|
pcl::PointNormal pt1, pt2;
|
|
pt1.x = pt2.x = i;
|
|
pt1.y = pt2.y = i;
|
|
pt1.z = pt2.z = i;
|
|
|
|
pt1.normal_x = pt2.normal_x = 1;
|
|
pt1.normal_y = pt2.normal_y = 0;
|
|
pt1.normal_z = pt2.normal_z = 0;
|
|
|
|
pt2.x += 100; // make them too far apart
|
|
|
|
cloud1->push_back(pt1);
|
|
cloud2->push_back(pt2);
|
|
}
|
|
|
|
double variance = -1.0;
|
|
int correspondences = -1;
|
|
|
|
util3d::computeVarianceAndCorrespondences(
|
|
cloud1, cloud2, 0.5, 0.0, variance, correspondences, true);
|
|
|
|
EXPECT_EQ(correspondences, 0);
|
|
EXPECT_DOUBLE_EQ(variance, 1.0); // default untouched
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, IcpIdentityTransformConverges)
|
|
{
|
|
auto cloud_source = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
for (float i = 0; i < 5; ++i)
|
|
{
|
|
cloud_source->push_back(pcl::PointXYZ(i, i * 2.0f, 0.0f));
|
|
}
|
|
|
|
auto cloud_target = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
*cloud_target = *cloud_source; // identical
|
|
|
|
bool hasConverged = false;
|
|
pcl::PointCloud<pcl::PointXYZ> aligned;
|
|
Transform result = util3d::icp(
|
|
cloud_source, cloud_target,
|
|
0.1, // max correspondence distance
|
|
50, // max iterations
|
|
hasConverged,
|
|
aligned,
|
|
1e-6f, // epsilon
|
|
false // 3D ICP
|
|
);
|
|
|
|
EXPECT_TRUE(hasConverged);
|
|
// ICP should return identity transform for identical clouds
|
|
Eigen::Matrix4f identity = Eigen::Matrix4f::Identity();
|
|
EXPECT_TRUE(result.toEigen4f().isApprox(identity, 1e-4));
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, IcpTranslatedTransformConverges)
|
|
{
|
|
auto cloud_source = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
for (float i = 0; i < 5; ++i)
|
|
{
|
|
cloud_source->push_back(pcl::PointXYZ(i, i * 2.0f, 0));
|
|
}
|
|
|
|
// Translate the cloud
|
|
Transform transformGT(0.025, 0, 0.0f ,0,0,0);
|
|
auto cloud_target = util3d::transformPointCloud(cloud_source, transformGT);
|
|
|
|
bool hasConverged = false;
|
|
pcl::PointCloud<pcl::PointXYZ> aligned;
|
|
Transform result = util3d::icp(
|
|
cloud_source, cloud_target,
|
|
0.05, 100, hasConverged, aligned,
|
|
1e-6f,
|
|
false
|
|
);
|
|
|
|
EXPECT_TRUE(hasConverged);
|
|
|
|
std::cout << result << std::endl;
|
|
std::cout << transformGT << std::endl;
|
|
|
|
Eigen::Matrix4f estimated = result.toEigen4f();
|
|
Eigen::Matrix4f expected = transformGT.toEigen4f();
|
|
EXPECT_TRUE(estimated.isApprox(expected, 1e-2));
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, Icp2DAlignsFlatClouds)
|
|
{
|
|
pcl::console::setVerbosityLevel(pcl::console::L_DEBUG);
|
|
auto cloud_source = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
for (float x = 0; x < 5; ++x)
|
|
{
|
|
for (float y = 0; y < 5; ++y)
|
|
{
|
|
if(y == 0 || y == 2 || y == 4 || x==0 || x==2 || x== 4){
|
|
cloud_source->push_back(pcl::PointXYZ(x*0.05, y*0.05, (int)x%2==0?0.01:-0.01));
|
|
}
|
|
}
|
|
}
|
|
|
|
Transform transformGT(0.075, 0.05, 0.01f, 0,0, M_PI / 8);
|
|
|
|
auto cloud_target = util3d::transformPointCloud(cloud_source, transformGT);
|
|
|
|
bool hasConverged = false;
|
|
pcl::PointCloud<pcl::PointXYZ> aligned;
|
|
Transform result = util3d::icp(
|
|
cloud_source, cloud_target,
|
|
0.15, 100, hasConverged, aligned,
|
|
1e-6f,
|
|
true // use ICP 2D
|
|
);
|
|
|
|
transformGT.z() = 0;
|
|
|
|
EXPECT_TRUE(hasConverged);
|
|
Eigen::Matrix4f estimated = result.toEigen4f();
|
|
Eigen::Matrix4f expected = transformGT.toEigen4f();
|
|
EXPECT_TRUE(estimated.isApprox(expected, 1e-4));
|
|
}
|
|
|
|
TEST(Util3dRegistrationTest, IcpPointToPlaneAlignsTranslatedPlane)
|
|
{
|
|
// Create a plane point cloud
|
|
auto cloud_source_raw = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
|
|
for (float x = -0.5f; x <= 0.5f; x += 0.1f)
|
|
{
|
|
for (float y = -0.5f; y <= 0.5f; y += 0.1f)
|
|
{
|
|
cloud_source_raw->push_back(pcl::PointXYZ(x, y, int(x*10)%2==0&&int(y*10)%2==0?0.01:-0.01));
|
|
}
|
|
}
|
|
|
|
// Compute normals
|
|
auto normals = util3d::computeNormals(cloud_source_raw, 20, 0, Eigen::Vector3f(0,0,1));
|
|
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_source(new pcl::PointCloud<pcl::PointNormal>);
|
|
pcl::concatenateFields(*cloud_source_raw, *normals, *cloud_source);
|
|
|
|
// Apply known transformation
|
|
Transform gtTransform(0.2f, -0.1f, 0.05f, 0.1f, 0, 0.1f);
|
|
|
|
auto cloud_target = util3d::transformPointCloud(cloud_source, gtTransform);
|
|
|
|
bool hasConverged = false;
|
|
pcl::PointCloud<pcl::PointNormal> aligned;
|
|
Transform estimated = util3d::icpPointToPlane(
|
|
cloud_source,
|
|
cloud_target,
|
|
0.2, // maxCorrespondenceDistance
|
|
50, // iterations
|
|
hasConverged,
|
|
aligned,
|
|
1e-6f, // epsilon
|
|
false // icp2D
|
|
);
|
|
|
|
std::cout << gtTransform << std::endl;
|
|
std::cout << estimated << std::endl;
|
|
|
|
EXPECT_TRUE(hasConverged);
|
|
Eigen::Matrix4f estimatedMatrix = estimated.toEigen4f();
|
|
Eigen::Matrix4f expectedMatrix = gtTransform.toEigen4f();
|
|
EXPECT_TRUE(estimatedMatrix.isApprox(expectedMatrix, 1e-4));
|
|
|
|
hasConverged = false;
|
|
estimated = util3d::icpPointToPlane(
|
|
cloud_source,
|
|
cloud_target,
|
|
0.2, // maxCorrespondenceDistance
|
|
50, // iterations
|
|
hasConverged,
|
|
aligned,
|
|
1e-6f, // epsilon
|
|
true // icp2D
|
|
);
|
|
|
|
// remove z and roll
|
|
gtTransform = Transform(0.2f, -0.1f, 0, 0, 0, 0.1f);
|
|
|
|
EXPECT_TRUE(hasConverged);
|
|
estimatedMatrix = estimated.toEigen4f();
|
|
expectedMatrix = gtTransform.toEigen4f();
|
|
EXPECT_TRUE(estimatedMatrix.isApprox(expectedMatrix, 1e-4));
|
|
} |