Commit 52dc573606f1d84aa06da30583f23680544acfca
1 parent
6298e600
New transform to filter gallery based on meta-data
Showing
1 changed file
with
36 additions
and
0 deletions
openbr/plugins/meta.cpp
| @@ -717,6 +717,42 @@ public: | @@ -717,6 +717,42 @@ public: | ||
| 717 | }; | 717 | }; |
| 718 | BR_REGISTER(Transform, DistributeTemplateTransform) | 718 | BR_REGISTER(Transform, DistributeTemplateTransform) |
| 719 | 719 | ||
| 720 | +/*! | ||
| 721 | + * \ingroup transforms | ||
| 722 | + * \brief Filters a gallery based on the value of a metadata field. | ||
| 723 | + * \author Brendan Klare \cite bklare | ||
| 724 | + */ | ||
| 725 | +class FilterOnMetadataTransform : public UntrainableMetaTransform | ||
| 726 | +{ | ||
| 727 | + Q_OBJECT | ||
| 728 | + Q_PROPERTY(QString attributeName READ get_attributeName WRITE set_attributeName RESET reset_attributeName STORED false) | ||
| 729 | + Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false) | ||
| 730 | + Q_PROPERTY(bool isGreaterThan READ get_isGreaterThan WRITE set_isGreaterThan RESET reset_isGreaterThan STORED false) | ||
| 731 | + BR_PROPERTY(QString, attributeName, "Confidence") | ||
| 732 | + BR_PROPERTY(float, threshold, 0) | ||
| 733 | + BR_PROPERTY(bool, isGreaterThan, true) | ||
| 734 | + | ||
| 735 | + void project(const TemplateList &src, TemplateList &dst) const | ||
| 736 | + { | ||
| 737 | + QList<Template> filtered; | ||
| 738 | + foreach (Template t, src) { | ||
| 739 | + if (!t.file.contains(attributeName)) | ||
| 740 | + continue; | ||
| 741 | + bool pass = t.file.get<float>(attributeName) > threshold; | ||
| 742 | + if (isGreaterThan ? pass : !pass) | ||
| 743 | + filtered.append(t); | ||
| 744 | + } | ||
| 745 | + dst = TemplateList(filtered); | ||
| 746 | + } | ||
| 747 | + | ||
| 748 | + void project(const Template &src, Template &dst) const | ||
| 749 | + { | ||
| 750 | + (void) src; (void) dst; qFatal("shouldn't be here"); | ||
| 751 | + } | ||
| 752 | +}; | ||
| 753 | + | ||
| 754 | +BR_REGISTER(Transform, FilterOnMetadataTransform) | ||
| 755 | + | ||
| 720 | } // namespace br | 756 | } // namespace br |
| 721 | 757 | ||
| 722 | #include "meta.moc" | 758 | #include "meta.moc" |