Commit e7625e5025f2840107089d5e8e8b4bb7c97e16d7
1 parent
36598e67
Moved FilterOnMetadata
Showing
2 changed files
with
36 additions
and
36 deletions
openbr/plugins/meta.cpp
| @@ -717,42 +717,6 @@ public: | @@ -717,42 +717,6 @@ 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 | - | ||
| 756 | } // namespace br | 720 | } // namespace br |
| 757 | 721 | ||
| 758 | #include "meta.moc" | 722 | #include "meta.moc" |
openbr/plugins/template.cpp
| @@ -50,6 +50,42 @@ class RemoveTemplatesTransform : public UntrainableMetaTransform | @@ -50,6 +50,42 @@ class RemoveTemplatesTransform : public UntrainableMetaTransform | ||
| 50 | 50 | ||
| 51 | BR_REGISTER(Transform, RemoveTemplatesTransform) | 51 | BR_REGISTER(Transform, RemoveTemplatesTransform) |
| 52 | 52 | ||
| 53 | +/*! | ||
| 54 | + * \ingroup transforms | ||
| 55 | + * \brief Filters a gallery based on the value of a metadata field. | ||
| 56 | + * \author Brendan Klare \cite bklare | ||
| 57 | + */ | ||
| 58 | +class FilterOnMetadataTransform : public UntrainableMetaTransform | ||
| 59 | +{ | ||
| 60 | + Q_OBJECT | ||
| 61 | + Q_PROPERTY(QString attributeName READ get_attributeName WRITE set_attributeName RESET reset_attributeName STORED false) | ||
| 62 | + Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false) | ||
| 63 | + Q_PROPERTY(bool isGreaterThan READ get_isGreaterThan WRITE set_isGreaterThan RESET reset_isGreaterThan STORED false) | ||
| 64 | + BR_PROPERTY(QString, attributeName, "Confidence") | ||
| 65 | + BR_PROPERTY(float, threshold, 0) | ||
| 66 | + BR_PROPERTY(bool, isGreaterThan, true) | ||
| 67 | + | ||
| 68 | + void project(const TemplateList &src, TemplateList &dst) const | ||
| 69 | + { | ||
| 70 | + QList<Template> filtered; | ||
| 71 | + foreach (Template t, src) { | ||
| 72 | + if (!t.file.contains(attributeName)) | ||
| 73 | + continue; | ||
| 74 | + bool pass = t.file.get<float>(attributeName) > threshold; | ||
| 75 | + if (isGreaterThan ? pass : !pass) | ||
| 76 | + filtered.append(t); | ||
| 77 | + } | ||
| 78 | + dst = TemplateList(filtered); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + void project(const Template &src, Template &dst) const | ||
| 82 | + { | ||
| 83 | + (void) src; (void) dst; qFatal("shouldn't be here"); | ||
| 84 | + } | ||
| 85 | +}; | ||
| 86 | + | ||
| 87 | +BR_REGISTER(Transform, FilterOnMetadataTransform) | ||
| 88 | + | ||
| 53 | } // namespace br | 89 | } // namespace br |
| 54 | 90 | ||
| 55 | #include "template.moc" | 91 | #include "template.moc" |