diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index 1faf8b5..a9eec23 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -522,30 +522,41 @@ struct AlgorithmCore private: QString name; - QString getFileName(const QString &description) const + // Check if description is either an abbreviation or a model file, if so load it + bool loadOrExpand(const QString &description) { - const QString file = Globals->sdkPath + "/share/openbr/models/algorithms/" + description; - QFileInfo qFile(file); - return qFile.exists() && !qFile.isDir() ? file : QString(); + // Check if a trained binary already exists for this algorithm + QString file = Globals->sdkPath + "/share/openbr/models/algorithms/" + description; + QFileInfo eFile(file); + file = eFile.exists() && !eFile.isDir() ? file : description; + + QFileInfo dFile(file); + if (dFile.exists() && !dFile.isDir()) { + qDebug("Loading %s", qPrintable(dFile.fileName())); + load(file); + return true; + } + + // Expand abbreviated algorithms to their full strings + if (Globals->abbreviations.contains(description)) { + init(Globals->abbreviations[description]); + return true; + } + return false; } void init(const QString &description) { - // Check if a trained binary already exists for this algorithm - const QString file = getFileName(description); - if (!file.isEmpty()) return init(file); + if (loadOrExpand(description)) + return; - QFileInfo dFile(description); - if (dFile.exists()) { - qDebug("Loading %s", qPrintable(dFile.fileName())); - load(description); + // 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; } - // Expand abbreviated algorithms to their full strings - if (Globals->abbreviations.contains(description)) - return init(Globals->abbreviations[description]); - const bool compareTransform = description.contains('!'); QStringList words = QtUtils::parse(description, compareTransform ? '!' : ':'); diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 3c0d05d..0d84260 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -38,6 +38,7 @@ #include "core/common.h" #include "core/opencvutils.h" #include "core/qtutils.h" +#include "openbr/plugins/openbr_internal.h" using namespace br; using namespace cv; @@ -721,7 +722,6 @@ bool Object::setPropertyRecursive(const QString &name, QVariant value) { if (this->metaObject()->indexOfProperty(qPrintable(name)) == -1) return false; - setProperty(name, value); init(); return true; @@ -1235,6 +1235,13 @@ Transform *Transform::make(QString str, QObject *parent) if (Globals->abbreviations.contains(str)) return make(Globals->abbreviations[str], parent); + File parsed("."+str); + if (Globals->abbreviations.contains(parsed.suffix())) { + Transform *res = make(Globals->abbreviations[parsed.suffix()], parent); + applyAdditionalProperties(parsed, res); + return res; + } + //! [Make a pipe] { // Check for use of '+' as shorthand for Pipe(...) QStringList words = parse(str, '+'); @@ -1435,3 +1442,14 @@ void Distance::compareBlock(const TemplateList &target, const TemplateList &quer if (target[j].isEmpty() || query[i].isEmpty()) output->setRelative(-std::numeric_limits::max(),i+queryOffset, j+targetOffset); else output->setRelative(compare(target[j], query[i]), i+queryOffset, j+targetOffset); } + +void br::applyAdditionalProperties(const File &temp, Transform *target) +{ + QVariantMap meta = temp.localMetadata(); + for (QVariantMap::iterator i = meta.begin(); i != meta.end(); ++i) { + if (i.key().startsWith("_Arg")) + continue; + + target->setPropertyRecursive(i.key(), i.value() ); + } +} diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index 085a0d5..2283760 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -385,6 +385,9 @@ public: qint64 position() { return f.pos(); } }; + +void applyAdditionalProperties(const File &temp, Transform *target); + } #endif // OPENBR_INTERNAL_H