diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index 2bbad5b..694bde3 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -522,41 +522,37 @@ struct AlgorithmCore private: QString name; - QString getFileName(const QString &description) const - { - const QString file = Globals->sdkPath + "/share/openbr/models/algorithms/" + description; - QFileInfo qFile(file); - return qFile.exists() && !qFile.isDir() ? file : QString(); - } - - void init(const QString &description) + // Check if description is either an abbreviation or a model file, if so load it + bool loadOrExpand(const QString & description) { // Check if a trained binary already exists for this algorithm - const QString file = getFileName(description); - if (!file.isEmpty()) return init(file); + QString file = Globals->sdkPath + "/share/openbr/models/algorithms/" + description; + QFileInfo eFile(file); + file = eFile.exists() && !eFile.isDir() ? file : description; - QFileInfo dFile(description); - if (dFile.exists()) { + QFileInfo dFile(file); + if (dFile.exists() && !dFile.isDir()) { qDebug("Loading %s", qPrintable(dFile.fileName())); - load(description); - return; + load(file); + return true; } - File parsed("."+description); - const QString parsedFname = getFileName(parsed.suffix()); - QFileInfo pFile(parsedFname); - if (pFile.exists()) { - load(parsedFname); - applyAdditionalProperties(parsed, transform.data()); - return; + // Expand abbreviated algorithms to their full strings + if (Globals->abbreviations.contains(description)) { + init(Globals->abbreviations[description]); + return true; } + return false; + } - // Expand abbreviated algorithms to their full strings - if (Globals->abbreviations.contains(description)) - return init(Globals->abbreviations[description]); + void init(const QString &description) + { + if (loadOrExpand(description)) + return; - if (Globals->abbreviations.contains(parsed.suffix())) { - init(Globals->abbreviations[parsed.suffix()]); + // check if the description is an abbreviation or model file with additional arguments supplied + File parsed("."+description); + if (loadOrExpand(parsed.suffix())) { applyAdditionalProperties(parsed, transform.data()); return; } diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 5c4544b..ef4ddb8 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -1443,7 +1443,7 @@ void Distance::compareBlock(const TemplateList &target, const TemplateList &quer else output->setRelative(compare(target[j], query[i]), i+queryOffset, j+targetOffset); } -void br::applyAdditionalProperties(File & temp, Transform * target) +void br::applyAdditionalProperties(const File &temp, Transform *target) { QVariantMap meta = temp.localMetadata(); for (QVariantMap::iterator i = meta.begin(); i != meta.end(); ++i) { diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index 2b86b9b..2283760 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -386,7 +386,7 @@ public: }; -void applyAdditionalProperties(File & temp, Transform * target); +void applyAdditionalProperties(const File &temp, Transform *target); }