From a18e803de42cbf3fc52c9f11985c7d2595285331 Mon Sep 17 00:00:00 2001 From: Fabien Servant Date: Mon, 13 Mar 2023 10:24:46 +0100 Subject: [PATCH] remove bug in getReferenceViewId --- src/software/utils/main_sfmTransform.cpp | 36 ++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/software/utils/main_sfmTransform.cpp b/src/software/utils/main_sfmTransform.cpp index e24af4b5af..20fe6ac1a7 100644 --- a/src/software/utils/main_sfmTransform.cpp +++ b/src/software/utils/main_sfmTransform.cpp @@ -186,26 +186,42 @@ static void parseManualTransform(const std::string& manualTransform, double& S, IndexT getReferenceViewId(const sfmData::SfMData & sfmData, const std::string & transform) { - IndexT refViewId; + IndexT refViewId; try { refViewId = sfm::getViewIdFromExpression(sfmData, transform); + if (!sfmData.isPoseAndIntrinsicDefined(refViewId)) + { + return UndefinedIndexT; + } } catch (...) { refViewId = UndefinedIndexT; } + //Default to select the view given timestamp if (refViewId == UndefinedIndexT) { - // Sort views per timestamps + // Sort views with poses per timestamps std::vector> sorted_views; for (auto v : sfmData.getViews()) { + if (!sfmData.isPoseAndIntrinsicDefined(v.first)) + { + continue; + } + int64_t t = v.second->getMetadataDateTimestamp(); sorted_views.push_back(std::make_pair(t, v.first)); } std::sort(sorted_views.begin(), sorted_views.end()); + if (sorted_views.size() == 0) + { + return UndefinedIndexT; + } + + // Get the view which was taken at the middle of the sequence int median = sorted_views.size() / 2; refViewId = sorted_views[sorted_views.size() - 1].second; @@ -299,6 +315,22 @@ int aliceVision_main(int argc, char **argv) return EXIT_FAILURE; } + //Check that at least one view has a defined pose + int count = 0; + for (const auto p : sfmData.getViews()) + { + if(sfmData.isPoseAndIntrinsicDefined(p.first)) + { + count++; + } + } + + if (count == 0) + { + ALICEVISION_LOG_ERROR("The input SfMData file '" << sfmDataFilename << "' has no valid views with estimated poses"); + return EXIT_FAILURE; + } + double S = 1.0; Mat3 R = Mat3::Identity(); Vec3 t = Vec3::Zero();