[LandmarkDetector] Make sure model paths are checked even when using FaceModelParameters default ctor

This commit is contained in:
Séverin Lemaignan 2018-03-20 14:29:07 +00:00
parent 0a769e4424
commit 6b65d012a2
2 changed files with 11 additions and 2 deletions

View File

@ -108,6 +108,7 @@ struct FaceModelParameters
private: private:
void init(); void init();
void check_model_path(const std::string& root="/");
}; };
} }

View File

@ -57,6 +57,7 @@ FaceModelParameters::FaceModelParameters()
{ {
// initialise the default values // initialise the default values
init(); init();
check_model_path();
} }
FaceModelParameters::FaceModelParameters(vector<string> &arguments) FaceModelParameters::FaceModelParameters(vector<string> &arguments)
@ -182,17 +183,24 @@ FaceModelParameters::FaceModelParameters(vector<string> &arguments)
} }
} }
check_model_path(root.string());
}
void FaceModelParameters::check_model_path(const std::string& root)
{
// Make sure model_location is valid // Make sure model_location is valid
// First check working directory, then the executable's directory, then the config path set by the build process. // 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 config_path = boost::filesystem::path(CONFIG_DIR);
boost::filesystem::path model_path = boost::filesystem::path(model_location); 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)) if (boost::filesystem::exists(model_path))
{ {
model_location = model_path.string(); 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)) else if (boost::filesystem::exists(config_path/model_path))
{ {