Commit b68b869c253d4ba4d12130d207a180c9411b15ea

Authored by caotto
2 parents ff8ebb8a 5dd00f58

Merge pull request #215 from biometrics/additional_arguments

Preliminary support for supplying additional arguments to algorithms
openbr/core/core.cpp
@@ -522,30 +522,41 @@ struct AlgorithmCore @@ -522,30 +522,41 @@ struct AlgorithmCore
522 private: 522 private:
523 QString name; 523 QString name;
524 524
525 - QString getFileName(const QString &description) const 525 + // Check if description is either an abbreviation or a model file, if so load it
  526 + bool loadOrExpand(const QString &description)
526 { 527 {
527 - const QString file = Globals->sdkPath + "/share/openbr/models/algorithms/" + description;  
528 - QFileInfo qFile(file);  
529 - return qFile.exists() && !qFile.isDir() ? file : QString(); 528 + // Check if a trained binary already exists for this algorithm
  529 + QString file = Globals->sdkPath + "/share/openbr/models/algorithms/" + description;
  530 + QFileInfo eFile(file);
  531 + file = eFile.exists() && !eFile.isDir() ? file : description;
  532 +
  533 + QFileInfo dFile(file);
  534 + if (dFile.exists() && !dFile.isDir()) {
  535 + qDebug("Loading %s", qPrintable(dFile.fileName()));
  536 + load(file);
  537 + return true;
  538 + }
  539 +
  540 + // Expand abbreviated algorithms to their full strings
  541 + if (Globals->abbreviations.contains(description)) {
  542 + init(Globals->abbreviations[description]);
  543 + return true;
  544 + }
  545 + return false;
530 } 546 }
531 547
532 void init(const QString &description) 548 void init(const QString &description)
533 { 549 {
534 - // Check if a trained binary already exists for this algorithm  
535 - const QString file = getFileName(description);  
536 - if (!file.isEmpty()) return init(file); 550 + if (loadOrExpand(description))
  551 + return;
537 552
538 - QFileInfo dFile(description);  
539 - if (dFile.exists()) {  
540 - qDebug("Loading %s", qPrintable(dFile.fileName()));  
541 - load(description); 553 + // check if the description is an abbreviation or model file with additional arguments supplied
  554 + File parsed("."+description);
  555 + if (loadOrExpand(parsed.suffix())) {
  556 + applyAdditionalProperties(parsed, transform.data());
542 return; 557 return;
543 } 558 }
544 559
545 - // Expand abbreviated algorithms to their full strings  
546 - if (Globals->abbreviations.contains(description))  
547 - return init(Globals->abbreviations[description]);  
548 -  
549 const bool compareTransform = description.contains('!'); 560 const bool compareTransform = description.contains('!');
550 QStringList words = QtUtils::parse(description, compareTransform ? '!' : ':'); 561 QStringList words = QtUtils::parse(description, compareTransform ? '!' : ':');
551 562
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(const 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(const File &temp, Transform *target);
  390 +
388 } 391 }
389 392
390 #endif // OPENBR_INTERNAL_H 393 #endif // OPENBR_INTERNAL_H