From bc8a1c44af31a0d2942997799702aa273f5398a6 Mon Sep 17 00:00:00 2001 From: Fabien Castan Date: Sun, 24 Mar 2024 17:54:18 +0100 Subject: [PATCH 1/2] [sfm] statistics: fix statistics to avoid troubles in particular cases --- src/aliceVision/sfm/sfmStatistics.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/aliceVision/sfm/sfmStatistics.cpp b/src/aliceVision/sfm/sfmStatistics.cpp index 6d5fc663f3..84ccc7d5b4 100644 --- a/src/aliceVision/sfm/sfmStatistics.cpp +++ b/src/aliceVision/sfm/sfmStatistics.cpp @@ -64,7 +64,11 @@ void computeResidualsHistogram(const sfmData::SfMData& sfmData, if (outHistogram) { - *outHistogram = utils::Histogram(0.0, std::ceil(outStats.max), std::ceil(outStats.max) * 2); + // clamp the max residu: + // - avoid errors in case of nonsense values + // - focus on the important residu, the small ones + const size_t maxValue = std::min(size_t(std::ceil(outStats.max)), size_t(30)); + *outHistogram = utils::Histogram(0.0, maxValue, maxValue * 5); outHistogram->Add(vecResiduals.begin(), vecResiduals.end()); } } @@ -122,7 +126,9 @@ void computeObservationsLengthsHistogram(const sfmData::SfMData& sfmData, if (outHistogram) { - *outHistogram = utils::Histogram(outStats.min, outStats.max + 1, outStats.max - outStats.min + 1); + // clamp the max to avoid errors in case of nonsense values + const size_t maxValue = std::min(size_t(std::ceil(outStats.max) + 1), size_t(1000)); + *outHistogram = utils::Histogram(0.0, maxValue, maxValue); outHistogram->Add(nbObservations.begin(), nbObservations.end()); } } @@ -166,8 +172,7 @@ void computeLandmarksPerViewHistogram(const sfmData::SfMData& sfmData, BoxStats< if (outHistogram) { - //*outHistogram = Histogram(0, sfmData.getViews().size(), sfmData.getViews().size()); - *outHistogram = utils::Histogram(outStats.min, (outStats.max + 1), 10); + *outHistogram = utils::Histogram(outStats.min, (outStats.max + 1), 50); outHistogram->Add(nbLandmarksPerViewVec.begin(), nbLandmarksPerViewVec.end()); } } @@ -304,6 +309,7 @@ void computeScaleHistogram(const sfmData::SfMData& sfmData, if (outHistogram) { size_t maxValue = std::ceil(outStats.max); + maxValue = std::min(maxValue, size_t(100)); // clamp max value in case of nonsense value *outHistogram = utils::Histogram(0.0, double(maxValue), maxValue + 1); outHistogram->Add(vecScaleObservations.begin(), vecScaleObservations.end()); } From 086455dcbe74630139258c58f8ec4f9589e8920f Mon Sep 17 00:00:00 2001 From: Fabien Castan Date: Sun, 24 Mar 2024 17:54:46 +0100 Subject: [PATCH 2/2] [sfm] statistics: remove unused vars --- src/aliceVision/sfm/sfmStatistics.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/aliceVision/sfm/sfmStatistics.cpp b/src/aliceVision/sfm/sfmStatistics.cpp index 84ccc7d5b4..b7b77d4f19 100644 --- a/src/aliceVision/sfm/sfmStatistics.cpp +++ b/src/aliceVision/sfm/sfmStatistics.cpp @@ -365,9 +365,6 @@ void computeResidualsPerView(const sfmData::SfMData& sfmData, continue; const std::vector& residuals = it->second; BoxStats residualStats(residuals.begin(), residuals.end()); - utils::Histogram residual_histogram = - utils::Histogram(residualStats.min, residualStats.max + 1, residualStats.max - residualStats.min + 1); - residual_histogram.Add(residuals.begin(), residuals.end()); nbResidualsPerViewMin[viewIdx] = residualStats.min; nbResidualsPerViewMax[viewIdx] = residualStats.max; @@ -420,9 +417,6 @@ void computeObservationsLengthsPerView(const sfmData::SfMData& sfmData, const IndexT viewId = viewKeys[viewIdx]; const std::vector& nbObservations = observationLengthsPerView[viewId]; BoxStats observationsLengthsStats(nbObservations.begin(), nbObservations.end()); - utils::Histogram observationsLengthsHistogram( - observationsLengthsStats.min, observationsLengthsStats.max + 1, observationsLengthsStats.max - observationsLengthsStats.min + 1); - observationsLengthsHistogram.Add(nbObservations.begin(), nbObservations.end()); nbObservationsLengthsPerViewMin[viewIdx] = observationsLengthsStats.min; nbObservationsLengthsPerViewMax[viewIdx] = observationsLengthsStats.max;