Commit ab563f109b8c2e53e2df741f6795ecdead8ec95e
1 parent
f04a4fa4
Preliminary support for supplying additional arguments to algorithms
Allow users to supply additional arguments to abbreviations or pre-trained algorithms (e.g. FaceRecogntion(a=b) is now possible). Arguments supplied must be key/value pairs, not positional. Any listed additional properties will be assigned to the first matching transform using a pre-order traversal of the algorithm tree.
Showing
3 changed files
with
37 additions
and
1 deletions
openbr/core/core.cpp
| @@ -542,10 +542,25 @@ private: | @@ -542,10 +542,25 @@ private: | ||
| 542 | return; | 542 | return; |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | + File parsed("."+description); | ||
| 546 | + const QString parsedFname = getFileName(parsed.suffix()); | ||
| 547 | + QFileInfo pFile(parsedFname); | ||
| 548 | + if (pFile.exists()) { | ||
| 549 | + load(parsedFname); | ||
| 550 | + applyAdditionalProperties(parsed, transform.data()); | ||
| 551 | + return; | ||
| 552 | + } | ||
| 553 | + | ||
| 545 | // Expand abbreviated algorithms to their full strings | 554 | // Expand abbreviated algorithms to their full strings |
| 546 | if (Globals->abbreviations.contains(description)) | 555 | if (Globals->abbreviations.contains(description)) |
| 547 | return init(Globals->abbreviations[description]); | 556 | return init(Globals->abbreviations[description]); |
| 548 | 557 | ||
| 558 | + if (Globals->abbreviations.contains(parsed.suffix())) { | ||
| 559 | + init(Globals->abbreviations[parsed.suffix()]); | ||
| 560 | + applyAdditionalProperties(parsed, transform.data()); | ||
| 561 | + return; | ||
| 562 | + } | ||
| 563 | + | ||
| 549 | const bool compareTransform = description.contains('!'); | 564 | const bool compareTransform = description.contains('!'); |
| 550 | QStringList words = QtUtils::parse(description, compareTransform ? '!' : ':'); | 565 | QStringList words = QtUtils::parse(description, compareTransform ? '!' : ':'); |
| 551 | 566 |
openbr/openbr_plugin.cpp
| @@ -38,6 +38,7 @@ | @@ -38,6 +38,7 @@ | ||
| 38 | #include "core/common.h" | 38 | #include "core/common.h" |
| 39 | #include "core/opencvutils.h" | 39 | #include "core/opencvutils.h" |
| 40 | #include "core/qtutils.h" | 40 | #include "core/qtutils.h" |
| 41 | +#include "openbr/plugins/openbr_internal.h" | ||
| 41 | 42 | ||
| 42 | using namespace br; | 43 | using namespace br; |
| 43 | using namespace cv; | 44 | using namespace cv; |
| @@ -721,7 +722,6 @@ bool Object::setPropertyRecursive(const QString &name, QVariant value) | @@ -721,7 +722,6 @@ bool Object::setPropertyRecursive(const QString &name, QVariant value) | ||
| 721 | { | 722 | { |
| 722 | if (this->metaObject()->indexOfProperty(qPrintable(name)) == -1) | 723 | if (this->metaObject()->indexOfProperty(qPrintable(name)) == -1) |
| 723 | return false; | 724 | return false; |
| 724 | - | ||
| 725 | setProperty(name, value); | 725 | setProperty(name, value); |
| 726 | init(); | 726 | init(); |
| 727 | return true; | 727 | return true; |
| @@ -1235,6 +1235,13 @@ Transform *Transform::make(QString str, QObject *parent) | @@ -1235,6 +1235,13 @@ Transform *Transform::make(QString str, QObject *parent) | ||
| 1235 | if (Globals->abbreviations.contains(str)) | 1235 | if (Globals->abbreviations.contains(str)) |
| 1236 | return make(Globals->abbreviations[str], parent); | 1236 | return make(Globals->abbreviations[str], parent); |
| 1237 | 1237 | ||
| 1238 | + File parsed("."+str); | ||
| 1239 | + if (Globals->abbreviations.contains(parsed.suffix())) { | ||
| 1240 | + Transform * res = make(Globals->abbreviations[parsed.suffix()], parent); | ||
| 1241 | + applyAdditionalProperties(parsed, res); | ||
| 1242 | + return res; | ||
| 1243 | + } | ||
| 1244 | + | ||
| 1238 | //! [Make a pipe] | 1245 | //! [Make a pipe] |
| 1239 | { // Check for use of '+' as shorthand for Pipe(...) | 1246 | { // Check for use of '+' as shorthand for Pipe(...) |
| 1240 | QStringList words = parse(str, '+'); | 1247 | QStringList words = parse(str, '+'); |
| @@ -1435,3 +1442,14 @@ void Distance::compareBlock(const TemplateList &target, const TemplateList &quer | @@ -1435,3 +1442,14 @@ void Distance::compareBlock(const TemplateList &target, const TemplateList &quer | ||
| 1435 | if (target[j].isEmpty() || query[i].isEmpty()) output->setRelative(-std::numeric_limits<float>::max(),i+queryOffset, j+targetOffset); | 1442 | if (target[j].isEmpty() || query[i].isEmpty()) output->setRelative(-std::numeric_limits<float>::max(),i+queryOffset, j+targetOffset); |
| 1436 | else output->setRelative(compare(target[j], query[i]), i+queryOffset, j+targetOffset); | 1443 | else output->setRelative(compare(target[j], query[i]), i+queryOffset, j+targetOffset); |
| 1437 | } | 1444 | } |
| 1445 | + | ||
| 1446 | +void br::applyAdditionalProperties(File & temp, Transform * target) | ||
| 1447 | +{ | ||
| 1448 | + QVariantMap meta = temp.localMetadata(); | ||
| 1449 | + for (QVariantMap::iterator i = meta.begin(); i != meta.end(); ++i) { | ||
| 1450 | + if (i.key().startsWith("_Arg")) | ||
| 1451 | + continue; | ||
| 1452 | + | ||
| 1453 | + target->setPropertyRecursive(i.key(), i.value() ); | ||
| 1454 | + } | ||
| 1455 | +} |
openbr/plugins/openbr_internal.h
| @@ -385,6 +385,9 @@ public: | @@ -385,6 +385,9 @@ public: | ||
| 385 | qint64 position() { return f.pos(); } | 385 | qint64 position() { return f.pos(); } |
| 386 | }; | 386 | }; |
| 387 | 387 | ||
| 388 | + | ||
| 389 | +void applyAdditionalProperties(File & temp, Transform * target); | ||
| 390 | + | ||
| 388 | } | 391 | } |
| 389 | 392 | ||
| 390 | #endif // OPENBR_INTERNAL_H | 393 | #endif // OPENBR_INTERNAL_H |