Commit 9afd250b2966b3e255ba40c4ccefc6e65f1a3bd1

Authored by bhklein
1 parent c9a7215f

option to project if metadata key doesn't exist

Showing 1 changed file with 7 additions and 5 deletions
openbr/plugins/imgproc/if.cpp
... ... @@ -15,10 +15,12 @@ class IfTransform : public MetaTransform
15 15 Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key)
16 16 Q_PROPERTY(QString value READ get_value WRITE set_value RESET reset_value)
17 17 Q_PROPERTY(QString comparison READ get_comparison WRITE set_comparison RESET reset_comparison)
  18 + Q_PROPERTY(bool projectOnEmpty READ get_projectOnEmpty WRITE set_projectOnEmpty RESET reset_projectOnEmpty)
18 19 BR_PROPERTY(br::Transform*, transform, NULL)
19 20 BR_PROPERTY(QString, key, "Label")
20 21 BR_PROPERTY(QString, value, "1")
21 22 BR_PROPERTY(QString, comparison, "e")
  23 + BR_PROPERTY(bool, projectOnEmpty, false)
22 24  
23 25 bool compare(const QString &metadata) const
24 26 {
... ... @@ -55,15 +57,15 @@ public:
55 57 if (transform->trainable) {
56 58 TemplateList passed;
57 59 for (int i=0; i<data.size(); i++)
58   - if (data[i].file.contains(key) && compare(data[i].file.get<QString>(key)))
  60 + if ((data[i].file.contains(key) || projectOnEmpty) && compare(data[i].file.get<QString>(key, QString())))
59 61 passed.append(data[i]);
60 62 transform->train(passed);
61 63 }
62 64 }
63 65  
64 66 void project(const Template &src, Template &dst) const {
65   - if (src.file.contains(key) && compare(src.file.get<QString>(key)))
66   - transform->project(src,dst);
  67 + if ((src.file.contains(key) || projectOnEmpty) && compare(src.file.get<QString>(key, QString())))
  68 + transform->project(src, dst);
67 69 else
68 70 dst = src;
69 71 }
... ... @@ -71,13 +73,13 @@ public:
71 73 void project(const TemplateList &src, TemplateList &dst) const {
72 74 TemplateList ifTrue, ifFalse;
73 75 foreach (const Template &t, src) {
74   - if (t.file.contains(key) && compare(t.file.get<QString>(key)))
  76 + if ((t.file.contains(key) || projectOnEmpty) && compare(t.file.get<QString>(key, QString())))
75 77 ifTrue.append(t);
76 78 else
77 79 ifFalse.append(t);
78 80 }
79 81  
80   - transform->project(ifTrue,dst);
  82 + transform->project(ifTrue, dst);
81 83 dst.append(ifFalse);
82 84 }
83 85  
... ...