From e194ad7d95872be8a30dc7793c6b331201fcb846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vital?= Date: Wed, 17 May 2023 10:56:24 +0200 Subject: [PATCH 1/4] [sfm] expose bundleAdjustmentMaxOutliers in engine params --- .../sequential/ReconstructionEngine_sequentialSfM.cpp | 2 +- .../sequential/ReconstructionEngine_sequentialSfM.hpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp index ed202f0976..a859c707ad 100644 --- a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp +++ b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp @@ -699,7 +699,7 @@ bool ReconstructionEngine_sequentialSfM::bundleAdjustment(std::set& newR if(!isInitialPair && !_params.lockAllIntrinsics) refineOptions |= BundleAdjustment::REFINE_INTRINSICS_ALL; - const std::size_t nbOutliersThreshold = (isInitialPair) ? 0 : 50; + const std::size_t nbOutliersThreshold = (isInitialPair) ? 0 : _params.bundleAdjustmentMaxOutliers; std::size_t iteration = 0; std::size_t nbOutliers = 0; bool enableLocalStrategy = false; diff --git a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.hpp b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.hpp index 06b335453e..e62428237b 100644 --- a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.hpp +++ b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.hpp @@ -85,6 +85,10 @@ class ReconstructionEngine_sequentialSfM : public ReconstructionEngine /// we don't add too much data in one step without bundle adjustment. std::size_t maxImagesPerGroup = 30; + /// Threshold for the maximum number of outliers allowed at the end of a BA iteration. + /// If the limit is not met, another BA iteration is performed. + std::size_t bundleAdjustmentMaxOutliers = 50; + // Local Bundle Adjustment data /// The minimum number of shared matches to create an edge between two views (nodes) From 670e50305fc149d0c774aaf66848a5b01b9f023c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vital?= Date: Wed, 17 May 2023 10:57:19 +0200 Subject: [PATCH 2/4] [pipeline] incrementalSfM: expose bundleAdjustmentMaxOutliers in command line --- src/software/pipeline/main_incrementalSfM.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/software/pipeline/main_incrementalSfM.cpp b/src/software/pipeline/main_incrementalSfM.cpp index 7d4e4c8418..532ec64972 100644 --- a/src/software/pipeline/main_incrementalSfM.cpp +++ b/src/software/pipeline/main_incrementalSfM.cpp @@ -27,7 +27,7 @@ // These constants define the current software version. // They must be updated when the command line is changed. #define ALICEVISION_SOFTWARE_VERSION_MAJOR 2 -#define ALICEVISION_SOFTWARE_VERSION_MINOR 2 +#define ALICEVISION_SOFTWARE_VERSION_MINOR 3 using namespace aliceVision; @@ -160,6 +160,8 @@ int aliceVision_main(int argc, char **argv) ("maxImagesPerGroup", po::value(&sfmParams.maxImagesPerGroup)->default_value(sfmParams.maxImagesPerGroup), "Maximum number of cameras that can be added before the bundle adjustment is performed. This prevents adding too much data " "at once without performing the bundle adjustment.") + ("bundleAdjustmentMaxOutliers", po::value(&sfmParams.bundleAdjustmentMaxOutliers)->default_value(sfmParams.bundleAdjustmentMaxOutliers), + "Threshold for the maximum number of outliers allowed at the end of a bundle adjustment iteration.") ("localizerEstimator", po::value(&sfmParams.localizerEstimator)->default_value(sfmParams.localizerEstimator), "Estimator type used to localize cameras (acransac (default), ransac, lsmeds, loransac, maxconsensus)") ("localizerEstimatorError", po::value(&sfmParams.localizerEstimatorError)->default_value(0.0), From fbd9ad7e67e4db17840df1589252405aed556b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vital?= Date: Wed, 17 May 2023 16:34:10 +0200 Subject: [PATCH 3/4] [sfm] allow negative bundleAdjustmentMaxOutliers to disable BA iterations --- .../sequential/ReconstructionEngine_sequentialSfM.cpp | 5 +++-- .../sequential/ReconstructionEngine_sequentialSfM.hpp | 3 ++- src/software/pipeline/main_incrementalSfM.cpp | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp index a859c707ad..19096614b6 100644 --- a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp +++ b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp @@ -699,7 +699,8 @@ bool ReconstructionEngine_sequentialSfM::bundleAdjustment(std::set& newR if(!isInitialPair && !_params.lockAllIntrinsics) refineOptions |= BundleAdjustment::REFINE_INTRINSICS_ALL; - const std::size_t nbOutliersThreshold = (isInitialPair) ? 0 : _params.bundleAdjustmentMaxOutliers; + const int nbOutliersThreshold = + (isInitialPair && _params.bundleAdjustmentMaxOutliers >= 0) ? 0 : _params.bundleAdjustmentMaxOutliers; std::size_t iteration = 0; std::size_t nbOutliers = 0; bool enableLocalStrategy = false; @@ -794,7 +795,7 @@ bool ReconstructionEngine_sequentialSfM::bundleAdjustment(std::set& newR ALICEVISION_LOG_INFO("Bundle adjustment iteration: " << iteration << " took " << std::chrono::duration_cast(std::chrono::steady_clock::now() - chronoItStart).count() << " msec."); ++iteration; } - while(nbOutliers > nbOutliersThreshold); + while(nbOutliersThreshold >= 0 && nbOutliers > nbOutliersThreshold); ALICEVISION_LOG_INFO("Bundle adjustment with " << iteration << " iterations took " << std::chrono::duration_cast(std::chrono::steady_clock::now() - chronoStart).count() << " msec."); return true; diff --git a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.hpp b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.hpp index e62428237b..c344e02b28 100644 --- a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.hpp +++ b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.hpp @@ -87,7 +87,8 @@ class ReconstructionEngine_sequentialSfM : public ReconstructionEngine /// Threshold for the maximum number of outliers allowed at the end of a BA iteration. /// If the limit is not met, another BA iteration is performed. - std::size_t bundleAdjustmentMaxOutliers = 50; + /// Using a negative value for this threshold will disable BA iterations. + int bundleAdjustmentMaxOutliers = 50; // Local Bundle Adjustment data diff --git a/src/software/pipeline/main_incrementalSfM.cpp b/src/software/pipeline/main_incrementalSfM.cpp index 532ec64972..2abf4d90ad 100644 --- a/src/software/pipeline/main_incrementalSfM.cpp +++ b/src/software/pipeline/main_incrementalSfM.cpp @@ -160,8 +160,9 @@ int aliceVision_main(int argc, char **argv) ("maxImagesPerGroup", po::value(&sfmParams.maxImagesPerGroup)->default_value(sfmParams.maxImagesPerGroup), "Maximum number of cameras that can be added before the bundle adjustment is performed. This prevents adding too much data " "at once without performing the bundle adjustment.") - ("bundleAdjustmentMaxOutliers", po::value(&sfmParams.bundleAdjustmentMaxOutliers)->default_value(sfmParams.bundleAdjustmentMaxOutliers), - "Threshold for the maximum number of outliers allowed at the end of a bundle adjustment iteration.") + ("bundleAdjustmentMaxOutliers", po::value(&sfmParams.bundleAdjustmentMaxOutliers)->default_value(sfmParams.bundleAdjustmentMaxOutliers), + "Threshold for the maximum number of outliers allowed at the end of a bundle adjustment iteration." + "Using a negative value for this threshold will disable BA iterations.") ("localizerEstimator", po::value(&sfmParams.localizerEstimator)->default_value(sfmParams.localizerEstimator), "Estimator type used to localize cameras (acransac (default), ransac, lsmeds, loransac, maxconsensus)") ("localizerEstimatorError", po::value(&sfmParams.localizerEstimatorError)->default_value(0.0), From 79ea6158716cf08bbed5c8cb58b80e21eb3170fd Mon Sep 17 00:00:00 2001 From: Fabien Castan Date: Wed, 17 May 2023 19:44:30 +0200 Subject: [PATCH 4/4] [sfm] BA for initial pair will still do BA iterations if there are some outliers --- .../pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp index 19096614b6..fa6a337e4f 100644 --- a/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp +++ b/src/aliceVision/sfm/pipeline/sequential/ReconstructionEngine_sequentialSfM.cpp @@ -700,7 +700,7 @@ bool ReconstructionEngine_sequentialSfM::bundleAdjustment(std::set& newR refineOptions |= BundleAdjustment::REFINE_INTRINSICS_ALL; const int nbOutliersThreshold = - (isInitialPair && _params.bundleAdjustmentMaxOutliers >= 0) ? 0 : _params.bundleAdjustmentMaxOutliers; + (isInitialPair) ? 0 : _params.bundleAdjustmentMaxOutliers; std::size_t iteration = 0; std::size_t nbOutliers = 0; bool enableLocalStrategy = false;