From 6b65d012a28e29196548fb343857352eb3aab9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verin=20Lemaignan?= Date: Tue, 20 Mar 2018 14:29:07 +0000 Subject: [PATCH] [LandmarkDetector] Make sure model paths are checked even when using FaceModelParameters default ctor --- .../include/LandmarkDetectorParameters.h | 1 + .../src/LandmarkDetectorParameters.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/local/LandmarkDetector/include/LandmarkDetectorParameters.h b/lib/local/LandmarkDetector/include/LandmarkDetectorParameters.h index f6fd0b1..afb165c 100644 --- a/lib/local/LandmarkDetector/include/LandmarkDetectorParameters.h +++ b/lib/local/LandmarkDetector/include/LandmarkDetectorParameters.h @@ -108,6 +108,7 @@ struct FaceModelParameters private: void init(); + void check_model_path(const std::string& root="/"); }; } diff --git a/lib/local/LandmarkDetector/src/LandmarkDetectorParameters.cpp b/lib/local/LandmarkDetector/src/LandmarkDetectorParameters.cpp index 798a2c4..6d30920 100644 --- a/lib/local/LandmarkDetector/src/LandmarkDetectorParameters.cpp +++ b/lib/local/LandmarkDetector/src/LandmarkDetectorParameters.cpp @@ -57,6 +57,7 @@ FaceModelParameters::FaceModelParameters() { // initialise the default values init(); + check_model_path(); } FaceModelParameters::FaceModelParameters(vector &arguments) @@ -182,17 +183,24 @@ FaceModelParameters::FaceModelParameters(vector &arguments) } } + check_model_path(root.string()); +} + +void FaceModelParameters::check_model_path(const std::string& root) +{ // Make sure model_location is valid // First check working directory, then the executable's directory, then the config path set by the build process. boost::filesystem::path config_path = boost::filesystem::path(CONFIG_DIR); boost::filesystem::path model_path = boost::filesystem::path(model_location); + boost::filesystem::path root_path = boost::filesystem::path(root); + if (boost::filesystem::exists(model_path)) { model_location = model_path.string(); } - else if (boost::filesystem::exists(root/model_path)) + else if (boost::filesystem::exists(root_path/model_path)) { - model_location = (root/model_path).string(); + model_location = (root_path/model_path).string(); } else if (boost::filesystem::exists(config_path/model_path)) {