Commit 4af37848c5751fa39f411bc133d207c9c8bde320
1 parent
6e514de3
Scores can be weighted prior to fusion with FuseDistance
Showing
1 changed file
with
7 additions
and
2 deletions
openbr/plugins/distance.cpp
| ... | ... | @@ -189,6 +189,7 @@ class FuseDistance : public Distance |
| 189 | 189 | Q_ENUMS(Operation) |
| 190 | 190 | Q_PROPERTY(QString description READ get_description WRITE set_description RESET reset_description STORED false) |
| 191 | 191 | Q_PROPERTY(Operation operation READ get_operation WRITE set_operation RESET reset_operation STORED false) |
| 192 | + Q_PROPERTY(QList<float> weights READ get_weights WRITE set_weights RESET reset_weights STORED false) | |
| 192 | 193 | |
| 193 | 194 | QList<br::Distance*> distances; |
| 194 | 195 | |
| ... | ... | @@ -199,6 +200,7 @@ public: |
| 199 | 200 | private: |
| 200 | 201 | BR_PROPERTY(QString, description, "IdenticalDistance") |
| 201 | 202 | BR_PROPERTY(Operation, operation, Mean) |
| 203 | + BR_PROPERTY(QList<float>, weights, QList<float>()) | |
| 202 | 204 | |
| 203 | 205 | void train(const TemplateList &src) |
| 204 | 206 | { |
| ... | ... | @@ -221,8 +223,11 @@ private: |
| 221 | 223 | if (a.size() != b.size()) qFatal("Comparison size mismatch"); |
| 222 | 224 | |
| 223 | 225 | QList<float> scores; |
| 224 | - for (int i=0; i<distances.size(); i++) | |
| 225 | - scores.append(distances[i]->compare(Template(a.file, a[i]),Template(b.file, b[i]))); | |
| 226 | + for (int i=0; i<distances.size(); i++) { | |
| 227 | + float weight; | |
| 228 | + weights.isEmpty() ? weight = 1. : weight = weights[i]; | |
| 229 | + scores.append(weight*distances[i]->compare(Template(a.file, a[i]),Template(b.file, b[i]))); | |
| 230 | + } | |
| 226 | 231 | |
| 227 | 232 | switch (operation) { |
| 228 | 233 | case Mean: | ... | ... |