From 3120187008abd7187cbd8994d8917ebc4839e431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 23 Jun 2024 14:01:15 +0000 Subject: [PATCH 1/6] Faster 7-point fundamental matrix estimator --- src/colmap/estimators/fundamental_matrix.cc | 66 +++++-------------- .../estimators/fundamental_matrix_test.cc | 20 +++--- 2 files changed, 27 insertions(+), 59 deletions(-) diff --git a/src/colmap/estimators/fundamental_matrix.cc b/src/colmap/estimators/fundamental_matrix.cc index 482f14e1ab..c58e6a506b 100644 --- a/src/colmap/estimators/fundamental_matrix.cc +++ b/src/colmap/estimators/fundamental_matrix.cc @@ -54,37 +54,23 @@ void FundamentalMatrixSevenPointEstimator::Estimate( models->clear(); - // Note that no normalization of the points is necessary here. - // Setup system of equations: [points2(i,:), 1]' * F * [points1(i,:), 1]'. - Eigen::Matrix A; + Eigen::Matrix A; for (size_t i = 0; i < 7; ++i) { - const double x0 = points1[i](0); - const double y0 = points1[i](1); - const double x1 = points2[i](0); - const double y1 = points2[i](1); - A(i, 0) = x1 * x0; - A(i, 1) = x1 * y0; - A(i, 2) = x1; - A(i, 3) = y1 * x0; - A(i, 4) = y1 * y0; - A(i, 5) = y1; - A(i, 6) = x0; - A(i, 7) = y0; - A(i, 8) = 1; + A.col(i) << points1[i].x() * points2[i].homogeneous(), + points1[i].y() * points2[i].homogeneous(), points2[i].homogeneous(); } // 9 unknowns with 7 equations, so we have 2D null space. - Eigen::JacobiSVD> svd(A, Eigen::ComputeFullV); - const Eigen::Matrix& f = svd.matrixV(); - Eigen::Matrix f1 = f.col(7); - Eigen::Matrix f2 = f.col(8); - - f1 -= f2; + Eigen::Matrix Q = A.fullPivHouseholderQr().matrixQ(); // Normalize, such that lambda + mu = 1 // and add constraint det(F) = det(lambda * f1 + (1 - lambda) * f2). + auto f1 = Q.col(7); + auto f2 = Q.col(8); + f1 -= f2; + const double t0 = f1(4) * f1(8) - f1(5) * f1(7); const double t1 = f1(3) * f1(8) - f1(5) * f1(6); const double t2 = f1(3) * f1(7) - f1(4) * f1(6); @@ -110,35 +96,17 @@ void FundamentalMatrixSevenPointEstimator::Estimate( f1(8) * (f2(0) * f2(4) - f2(1) * f2(3)); coeffs(3) = f2(0) * t3 - f2(1) * t4 + f2(2) * t5; - Eigen::VectorXd roots_real; - Eigen::VectorXd roots_imag; - if (!FindPolynomialRootsCompanionMatrix(coeffs, &roots_real, &roots_imag)) { - return; - } - - models->reserve(roots_real.size()); - - for (Eigen::VectorXd::Index i = 0; i < roots_real.size(); ++i) { - const double kMaxRootImag = 1e-10; - if (std::abs(roots_imag(i)) > kMaxRootImag) { - continue; - } - - const double lambda = roots_real(i); - const double mu = 1; - - Eigen::MatrixXd F = lambda * f1 + mu * f2; - - F.resize(3, 3); - - const double kEps = 1e-10; - if (std::abs(F(2, 2)) < kEps) { - continue; - } + const double inv_c0 = 1.0 / coeffs(0); + coeffs.tail<3>() *= inv_c0; - F /= F(2, 2); + Eigen::Vector3d roots; + const int num_roots = + FindCubicPolynomialRoots(coeffs(1), coeffs(2), coeffs(3), &roots); - models->push_back(F.transpose()); + models->reserve(num_roots); + for (int i = 0; i < num_roots; ++i) { + const Eigen::Matrix F = (f1 * roots[i] + f2).normalized(); + models->push_back(Eigen::Map(F.data())); } } diff --git a/src/colmap/estimators/fundamental_matrix_test.cc b/src/colmap/estimators/fundamental_matrix_test.cc index 5804eda1f1..60b5404eba 100644 --- a/src/colmap/estimators/fundamental_matrix_test.cc +++ b/src/colmap/estimators/fundamental_matrix_test.cc @@ -79,7 +79,7 @@ TEST(FundamentalMatrix, SevenPoint) { estimator.Estimate(points1, points2, &models); ASSERT_EQ(models.size(), 1); - const auto& F = models[0]; + const Eigen::Matrix3d F = models[0] / models[0](2, 2); // Reference values obtained from Matlab. EXPECT_NEAR(F(0, 0), 4.81441976, 1e-6); @@ -146,15 +146,15 @@ TEST(FundamentalMatrix, EightPoint) { const auto& F = models[0]; // Reference values obtained from Matlab. - EXPECT_TRUE(std::abs(F(0, 0) - -0.217859) < 1e-5); - EXPECT_TRUE(std::abs(F(0, 1) - 0.419282) < 1e-5); - EXPECT_TRUE(std::abs(F(0, 2) - -0.0343075) < 1e-5); - EXPECT_TRUE(std::abs(F(1, 0) - -0.0717941) < 1e-5); - EXPECT_TRUE(std::abs(F(1, 1) - 0.0451643) < 1e-5); - EXPECT_TRUE(std::abs(F(1, 2) - 0.0216073) < 1e-5); - EXPECT_TRUE(std::abs(F(2, 0) - 0.248062) < 1e-5); - EXPECT_TRUE(std::abs(F(2, 1) - -0.429478) < 1e-5); - EXPECT_TRUE(std::abs(F(2, 2) - 0.0221019) < 1e-5); + EXPECT_NEAR(F(0, 0), -0.217859, 1e-5); + EXPECT_NEAR(F(0, 1), 0.419282, 1e-5); + EXPECT_NEAR(F(0, 2), -0.0343075, 1e-5); + EXPECT_NEAR(F(1, 0), -0.0717941, 1e-5); + EXPECT_NEAR(F(1, 1), 0.0451643, 1e-5); + EXPECT_NEAR(F(1, 2), 0.0216073, 1e-5); + EXPECT_NEAR(F(2, 0), 0.248062, 1e-5); + EXPECT_NEAR(F(2, 1), -0.429478, 1e-5); + EXPECT_NEAR(F(2, 2), 0.0221019, 1e-5); } } // namespace From e7e2fb6c5ff14c1d27406955a563bc21d7240544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 23 Jun 2024 21:40:19 +0000 Subject: [PATCH 2/6] tests --- src/colmap/estimators/fundamental_matrix.cc | 21 +++-- .../estimators/fundamental_matrix_test.cc | 87 ++++++++++++++++++- 2 files changed, 101 insertions(+), 7 deletions(-) diff --git a/src/colmap/estimators/fundamental_matrix.cc b/src/colmap/estimators/fundamental_matrix.cc index c58e6a506b..20732aa2bf 100644 --- a/src/colmap/estimators/fundamental_matrix.cc +++ b/src/colmap/estimators/fundamental_matrix.cc @@ -96,12 +96,23 @@ void FundamentalMatrixSevenPointEstimator::Estimate( f1(8) * (f2(0) * f2(4) - f2(1) * f2(3)); coeffs(3) = f2(0) * t3 - f2(1) * t4 + f2(2) * t5; - const double inv_c0 = 1.0 / coeffs(0); - coeffs.tail<3>() *= inv_c0; - Eigen::Vector3d roots; - const int num_roots = - FindCubicPolynomialRoots(coeffs(1), coeffs(2), coeffs(3), &roots); + int num_roots = 0; + if (std::abs(coeffs(0)) <= 1e-6) { + Eigen::VectorXd roots_real; + Eigen::VectorXd roots_imag; + FindQuadraticPolynomialRoots(coeffs.tail<3>(), &roots_real, &roots_imag); + for (int i = 0; i < roots_real.size(); ++i) { + if (std::abs(roots_imag(i)) <= 1e-6) { + roots(num_roots++) = roots_real(i); + } + } + } else { + const double inv_c0 = 1.0 / coeffs(0); + coeffs.tail<3>() *= inv_c0; + num_roots = + FindCubicPolynomialRoots(coeffs(1), coeffs(2), coeffs(3), &roots); + } models->reserve(num_roots); for (int i = 0; i < num_roots; ++i) { diff --git a/src/colmap/estimators/fundamental_matrix_test.cc b/src/colmap/estimators/fundamental_matrix_test.cc index 60b5404eba..23bf813fb5 100644 --- a/src/colmap/estimators/fundamental_matrix_test.cc +++ b/src/colmap/estimators/fundamental_matrix_test.cc @@ -29,12 +29,14 @@ #include "colmap/estimators/fundamental_matrix.h" +#include "colmap/geometry/essential_matrix.h" + #include namespace colmap { namespace { -TEST(FundamentalMatrix, SevenPoint) { +TEST(FundamentalSevenPointEstimator, Reference) { const double points1_raw[] = {0.4964, 1.0577, 0.3650, @@ -93,7 +95,44 @@ TEST(FundamentalMatrix, SevenPoint) { EXPECT_NEAR(F(2, 2), 1., 1e-6); } -TEST(FundamentalMatrix, EightPoint) { +TEST(FundamentalSevenPointEstimator, Nominal) { + const size_t kNumPoints = 7; + const Eigen::Matrix3d K = + (Eigen::Matrix3d() << 1000, 0, 500, 0, 1000, 500, 0, 0, 1).finished(); + for (size_t k = 0; k < 10; ++k) { + const Rigid3d cam2_from_cam1(Eigen::Quaterniond::UnitRandom(), + Eigen::Vector3d::Random()); + Eigen::Matrix3d expected_F = FundamentalFromEssentialMatrix( + K, EssentialMatrixFromPose(cam2_from_cam1), K); + expected_F /= expected_F(2, 2); + std::vector points1; + std::vector points2; + for (size_t i = 0; i < kNumPoints; ++i) { + points1.push_back(K.topRows<2>() * + Eigen::Vector2d::Random().homogeneous()); + const double random_depth = 1 + rand() / static_cast(RAND_MAX); + points2.push_back((K * (cam2_from_cam1 * (random_depth * K.inverse() * + points1.back().homogeneous()))) + .hnormalized()); + } + + FundamentalMatrixSevenPointEstimator estimator; + std::vector models; + estimator.Estimate(points1, points2, &models); + + bool found = false; + for (Eigen::Matrix3d& F : models) { + F /= F(2, 2); + if (F.isApprox(expected_F, 1e-3)) { + found = true; + break; + } + } + EXPECT_TRUE(found); + } +} + +TEST(FundamentalMatrixEightPointEstimator, Reference) { const double points1_raw[] = {1.839035, 1.924743, 0.543582, @@ -157,5 +196,49 @@ TEST(FundamentalMatrix, EightPoint) { EXPECT_NEAR(F(2, 2), 0.0221019, 1e-5); } +class FundamentalMatrixEightPointEstimatorTests + : public ::testing::TestWithParam {}; + +TEST_P(FundamentalMatrixEightPointEstimatorTests, Nominal) { + const size_t kNumPoints = GetParam(); + const Eigen::Matrix3d K = + (Eigen::Matrix3d() << 1000, 0, 500, 0, 1000, 500, 0, 0, 1).finished(); + for (size_t k = 0; k < 10; ++k) { + const Rigid3d cam2_from_cam1(Eigen::Quaterniond::UnitRandom(), + Eigen::Vector3d::Random()); + Eigen::Matrix3d expected_F = FundamentalFromEssentialMatrix( + K, EssentialMatrixFromPose(cam2_from_cam1), K); + expected_F /= expected_F(2, 2); + std::vector points1; + std::vector points2; + for (size_t i = 0; i < kNumPoints; ++i) { + points1.push_back(K.topRows<2>() * + Eigen::Vector2d::Random().homogeneous()); + const double random_depth = 1 + rand() / static_cast(RAND_MAX); + points2.push_back((K * (cam2_from_cam1 * (random_depth * K.inverse() * + points1.back().homogeneous()))) + .hnormalized()); + } + + FundamentalMatrixEightPointEstimator estimator; + std::vector models; + estimator.Estimate(points1, points2, &models); + + bool found = false; + for (Eigen::Matrix3d& F : models) { + F /= F(2, 2); + if (F.isApprox(expected_F, 1e-3)) { + found = true; + break; + } + } + EXPECT_TRUE(found); + } +} + +INSTANTIATE_TEST_SUITE_P(FundamentalMatrixEightPointEstimator, + FundamentalMatrixEightPointEstimatorTests, + ::testing::Values(8, 16, 32)); + } // namespace } // namespace colmap From ca9bf97f68f94f042b6c9addf333d3240d8c6464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 24 Jun 2024 07:22:29 +0000 Subject: [PATCH 3/6] d --- src/colmap/estimators/fundamental_matrix.cc | 24 +++++++------------ .../estimators/fundamental_matrix_test.cc | 5 ++-- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/colmap/estimators/fundamental_matrix.cc b/src/colmap/estimators/fundamental_matrix.cc index 20732aa2bf..6589375a80 100644 --- a/src/colmap/estimators/fundamental_matrix.cc +++ b/src/colmap/estimators/fundamental_matrix.cc @@ -80,6 +80,10 @@ void FundamentalMatrixSevenPointEstimator::Estimate( Eigen::Vector4d coeffs; coeffs(0) = f1(0) * t0 - f1(1) * t1 + f1(2) * t2; + if (std::abs(coeffs(0)) < 1e-16) { + return; + } + coeffs(1) = f2(0) * t0 - f2(1) * t1 + f2(2) * t2 - f2(3) * (f1(1) * f1(8) - f1(2) * f1(7)) + f2(4) * (f1(0) * f1(8) - f1(2) * f1(6)) - @@ -96,23 +100,11 @@ void FundamentalMatrixSevenPointEstimator::Estimate( f1(8) * (f2(0) * f2(4) - f2(1) * f2(3)); coeffs(3) = f2(0) * t3 - f2(1) * t4 + f2(2) * t5; + coeffs.tail<3>() /= coeffs(0); + Eigen::Vector3d roots; - int num_roots = 0; - if (std::abs(coeffs(0)) <= 1e-6) { - Eigen::VectorXd roots_real; - Eigen::VectorXd roots_imag; - FindQuadraticPolynomialRoots(coeffs.tail<3>(), &roots_real, &roots_imag); - for (int i = 0; i < roots_real.size(); ++i) { - if (std::abs(roots_imag(i)) <= 1e-6) { - roots(num_roots++) = roots_real(i); - } - } - } else { - const double inv_c0 = 1.0 / coeffs(0); - coeffs.tail<3>() *= inv_c0; - num_roots = - FindCubicPolynomialRoots(coeffs(1), coeffs(2), coeffs(3), &roots); - } + const int num_roots = + FindCubicPolynomialRoots(coeffs(1), coeffs(2), coeffs(3), &roots); models->reserve(num_roots); for (int i = 0; i < num_roots; ++i) { diff --git a/src/colmap/estimators/fundamental_matrix_test.cc b/src/colmap/estimators/fundamental_matrix_test.cc index 23bf813fb5..744ad50e5a 100644 --- a/src/colmap/estimators/fundamental_matrix_test.cc +++ b/src/colmap/estimators/fundamental_matrix_test.cc @@ -30,6 +30,7 @@ #include "colmap/estimators/fundamental_matrix.h" #include "colmap/geometry/essential_matrix.h" +#include "colmap/math/random.h" #include @@ -110,7 +111,7 @@ TEST(FundamentalSevenPointEstimator, Nominal) { for (size_t i = 0; i < kNumPoints; ++i) { points1.push_back(K.topRows<2>() * Eigen::Vector2d::Random().homogeneous()); - const double random_depth = 1 + rand() / static_cast(RAND_MAX); + const double random_depth = RandomUniformReal(0.2, 2.0); points2.push_back((K * (cam2_from_cam1 * (random_depth * K.inverse() * points1.back().homogeneous()))) .hnormalized()); @@ -214,7 +215,7 @@ TEST_P(FundamentalMatrixEightPointEstimatorTests, Nominal) { for (size_t i = 0; i < kNumPoints; ++i) { points1.push_back(K.topRows<2>() * Eigen::Vector2d::Random().homogeneous()); - const double random_depth = 1 + rand() / static_cast(RAND_MAX); + const double random_depth = RandomUniformReal(0.2, 2.0); points2.push_back((K * (cam2_from_cam1 * (random_depth * K.inverse() * points1.back().homogeneous()))) .hnormalized()); From 93d859e883837a6b0d161f39e7298f5ae6724f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 24 Jun 2024 07:34:33 +0000 Subject: [PATCH 4/6] d --- .../estimators/fundamental_matrix_test.cc | 107 ++++++++++-------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/src/colmap/estimators/fundamental_matrix_test.cc b/src/colmap/estimators/fundamental_matrix_test.cc index 744ad50e5a..5e74abccab 100644 --- a/src/colmap/estimators/fundamental_matrix_test.cc +++ b/src/colmap/estimators/fundamental_matrix_test.cc @@ -37,6 +37,47 @@ namespace colmap { namespace { +Eigen::Matrix3d RandomCalibrationMatrix() { + return (Eigen::Matrix3d() << RandomUniformReal(800, 1200), + 0, + RandomUniformReal(400, 600), + 0, + RandomUniformReal(800, 1200), + RandomUniformReal(400, 600), + 0, + 0, + 1) + .finished(); +} + +std::pair, std::vector> +RandomEpipolarCorrespondences(const Rigid3d& cam2_from_cam1, + const Eigen::Matrix3d& K, + size_t num_points) { + std::vector points1; + std::vector points2; + for (size_t i = 0; i < num_points; ++i) { + points1.push_back(K.topRows<2>() * Eigen::Vector2d::Random().homogeneous()); + const double random_depth = RandomUniformReal(0.2, 2.0); + points2.push_back((K * (cam2_from_cam1 * (random_depth * K.inverse() * + points1.back().homogeneous()))) + .hnormalized()); + } + return {std::move(points1), std::move(points2)}; +} + +void ExpectAtLeastOneEqualFundamentalUpToScale( + Eigen::Matrix3d& F, std::vector& Fs) { + F /= F(2, 2); + for (Eigen::Matrix3d& F_candidate : Fs) { + F_candidate /= F_candidate(2, 2); + if (F_candidate.isApprox(F, 1e-6)) { + return; + } + } + FAIL() << "No fundamental matrix is equal up to scale."; +} + TEST(FundamentalSevenPointEstimator, Reference) { const double points1_raw[] = {0.4964, 1.0577, @@ -98,38 +139,21 @@ TEST(FundamentalSevenPointEstimator, Reference) { TEST(FundamentalSevenPointEstimator, Nominal) { const size_t kNumPoints = 7; - const Eigen::Matrix3d K = - (Eigen::Matrix3d() << 1000, 0, 500, 0, 1000, 500, 0, 0, 1).finished(); - for (size_t k = 0; k < 10; ++k) { - const Rigid3d cam2_from_cam1(Eigen::Quaterniond::UnitRandom(), - Eigen::Vector3d::Random()); + for (size_t k = 0; k < 100; ++k) { + const Eigen::Matrix3d K = RandomCalibrationMatrix(); + const Rigid3d cam2_from_cam1( + Eigen::Quaterniond::UnitRandom(), + Eigen::Vector3d(2, 2, 2) + Eigen::Vector3d::Random()); Eigen::Matrix3d expected_F = FundamentalFromEssentialMatrix( K, EssentialMatrixFromPose(cam2_from_cam1), K); - expected_F /= expected_F(2, 2); - std::vector points1; - std::vector points2; - for (size_t i = 0; i < kNumPoints; ++i) { - points1.push_back(K.topRows<2>() * - Eigen::Vector2d::Random().homogeneous()); - const double random_depth = RandomUniformReal(0.2, 2.0); - points2.push_back((K * (cam2_from_cam1 * (random_depth * K.inverse() * - points1.back().homogeneous()))) - .hnormalized()); - } + const auto [points1, points2] = + RandomEpipolarCorrespondences(cam2_from_cam1, K, kNumPoints); FundamentalMatrixSevenPointEstimator estimator; std::vector models; estimator.Estimate(points1, points2, &models); - bool found = false; - for (Eigen::Matrix3d& F : models) { - F /= F(2, 2); - if (F.isApprox(expected_F, 1e-3)) { - found = true; - break; - } - } - EXPECT_TRUE(found); + ExpectAtLeastOneEqualFundamentalUpToScale(expected_F, models); } } @@ -202,38 +226,21 @@ class FundamentalMatrixEightPointEstimatorTests TEST_P(FundamentalMatrixEightPointEstimatorTests, Nominal) { const size_t kNumPoints = GetParam(); - const Eigen::Matrix3d K = - (Eigen::Matrix3d() << 1000, 0, 500, 0, 1000, 500, 0, 0, 1).finished(); - for (size_t k = 0; k < 10; ++k) { - const Rigid3d cam2_from_cam1(Eigen::Quaterniond::UnitRandom(), - Eigen::Vector3d::Random()); + for (size_t k = 0; k < 100; ++k) { + const Eigen::Matrix3d K = RandomCalibrationMatrix(); + const Rigid3d cam2_from_cam1( + Eigen::Quaterniond::UnitRandom(), + Eigen::Vector3d(2, 2, 2) + Eigen::Vector3d::Random()); Eigen::Matrix3d expected_F = FundamentalFromEssentialMatrix( K, EssentialMatrixFromPose(cam2_from_cam1), K); - expected_F /= expected_F(2, 2); - std::vector points1; - std::vector points2; - for (size_t i = 0; i < kNumPoints; ++i) { - points1.push_back(K.topRows<2>() * - Eigen::Vector2d::Random().homogeneous()); - const double random_depth = RandomUniformReal(0.2, 2.0); - points2.push_back((K * (cam2_from_cam1 * (random_depth * K.inverse() * - points1.back().homogeneous()))) - .hnormalized()); - } + const auto [points1, points2] = + RandomEpipolarCorrespondences(cam2_from_cam1, K, kNumPoints); FundamentalMatrixEightPointEstimator estimator; std::vector models; estimator.Estimate(points1, points2, &models); - bool found = false; - for (Eigen::Matrix3d& F : models) { - F /= F(2, 2); - if (F.isApprox(expected_F, 1e-3)) { - found = true; - break; - } - } - EXPECT_TRUE(found); + ExpectAtLeastOneEqualFundamentalUpToScale(expected_F, models); } } From fd48dfe54240817c30dbb34494a1a71a8f77f6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 24 Jun 2024 07:36:54 +0000 Subject: [PATCH 5/6] d --- src/colmap/estimators/fundamental_matrix_test.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/colmap/estimators/fundamental_matrix_test.cc b/src/colmap/estimators/fundamental_matrix_test.cc index 5e74abccab..3fd293c70f 100644 --- a/src/colmap/estimators/fundamental_matrix_test.cc +++ b/src/colmap/estimators/fundamental_matrix_test.cc @@ -141,9 +141,8 @@ TEST(FundamentalSevenPointEstimator, Nominal) { const size_t kNumPoints = 7; for (size_t k = 0; k < 100; ++k) { const Eigen::Matrix3d K = RandomCalibrationMatrix(); - const Rigid3d cam2_from_cam1( - Eigen::Quaterniond::UnitRandom(), - Eigen::Vector3d(2, 2, 2) + Eigen::Vector3d::Random()); + const Rigid3d cam2_from_cam1(Eigen::Quaterniond::UnitRandom(), + Eigen::Vector3d::Random()); Eigen::Matrix3d expected_F = FundamentalFromEssentialMatrix( K, EssentialMatrixFromPose(cam2_from_cam1), K); const auto [points1, points2] = @@ -228,9 +227,8 @@ TEST_P(FundamentalMatrixEightPointEstimatorTests, Nominal) { const size_t kNumPoints = GetParam(); for (size_t k = 0; k < 100; ++k) { const Eigen::Matrix3d K = RandomCalibrationMatrix(); - const Rigid3d cam2_from_cam1( - Eigen::Quaterniond::UnitRandom(), - Eigen::Vector3d(2, 2, 2) + Eigen::Vector3d::Random()); + const Rigid3d cam2_from_cam1(Eigen::Quaterniond::UnitRandom(), + Eigen::Vector3d::Random()); Eigen::Matrix3d expected_F = FundamentalFromEssentialMatrix( K, EssentialMatrixFromPose(cam2_from_cam1), K); const auto [points1, points2] = From 9a3e8500fbb78e5f6cb538856d56c88bae2ceff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 24 Jun 2024 07:51:02 +0000 Subject: [PATCH 6/6] msvc --- .../estimators/fundamental_matrix_test.cc | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/colmap/estimators/fundamental_matrix_test.cc b/src/colmap/estimators/fundamental_matrix_test.cc index 3fd293c70f..e1a9d970a8 100644 --- a/src/colmap/estimators/fundamental_matrix_test.cc +++ b/src/colmap/estimators/fundamental_matrix_test.cc @@ -50,12 +50,11 @@ Eigen::Matrix3d RandomCalibrationMatrix() { .finished(); } -std::pair, std::vector> -RandomEpipolarCorrespondences(const Rigid3d& cam2_from_cam1, - const Eigen::Matrix3d& K, - size_t num_points) { - std::vector points1; - std::vector points2; +void RandomEpipolarCorrespondences(const Rigid3d& cam2_from_cam1, + const Eigen::Matrix3d& K, + size_t num_points, + std::vector& points1, + std::vector& points2) { for (size_t i = 0; i < num_points; ++i) { points1.push_back(K.topRows<2>() * Eigen::Vector2d::Random().homogeneous()); const double random_depth = RandomUniformReal(0.2, 2.0); @@ -63,7 +62,6 @@ RandomEpipolarCorrespondences(const Rigid3d& cam2_from_cam1, points1.back().homogeneous()))) .hnormalized()); } - return {std::move(points1), std::move(points2)}; } void ExpectAtLeastOneEqualFundamentalUpToScale( @@ -145,8 +143,10 @@ TEST(FundamentalSevenPointEstimator, Nominal) { Eigen::Vector3d::Random()); Eigen::Matrix3d expected_F = FundamentalFromEssentialMatrix( K, EssentialMatrixFromPose(cam2_from_cam1), K); - const auto [points1, points2] = - RandomEpipolarCorrespondences(cam2_from_cam1, K, kNumPoints); + std::vector points1; + std::vector points2; + RandomEpipolarCorrespondences( + cam2_from_cam1, K, kNumPoints, points1, points2); FundamentalMatrixSevenPointEstimator estimator; std::vector models; @@ -231,8 +231,10 @@ TEST_P(FundamentalMatrixEightPointEstimatorTests, Nominal) { Eigen::Vector3d::Random()); Eigen::Matrix3d expected_F = FundamentalFromEssentialMatrix( K, EssentialMatrixFromPose(cam2_from_cam1), K); - const auto [points1, points2] = - RandomEpipolarCorrespondences(cam2_from_cam1, K, kNumPoints); + std::vector points1; + std::vector points2; + RandomEpipolarCorrespondences( + cam2_from_cam1, K, kNumPoints, points1, points2); FundamentalMatrixEightPointEstimator estimator; std::vector models;