diff --git a/sdk/openbr_plugin.cpp b/sdk/openbr_plugin.cpp index 4c0b19a..666437c 100644 --- a/sdk/openbr_plugin.cpp +++ b/sdk/openbr_plugin.cpp @@ -1315,22 +1315,13 @@ void Distance::compare(const TemplateList &target, const TemplateList &query, Ou float Distance::compare(const Template &target, const Template &query) const { - if (!Globals->demographicFilters.isEmpty()) { - // The if statement is a faster check then iterating over an empty list of filters - foreach (const QString &filter, Globals->demographicFilters) { + if (!Globals->demographicFilters.isEmpty()) // If statement is faster than iterating over an empty list of filters + foreach (const QString &filter, Globals->demographicFilters.keys()) { const QString targetMetadata = target.file.getString(filter, ""); - const QString queryMetadata = query.file.getString(filter, ""); - if (targetMetadata.isEmpty() || queryMetadata.isEmpty()) continue; - if (targetMetadata != queryMetadata) return -std::numeric_limits::max(); + if (!targetMetadata.isEmpty() && + (Globals->demographicFilters[filter].indexIn(targetMetadata) == -1)) + return -std::numeric_limits::max(); } - } - - if (Globals->ageDelta < std::numeric_limits::max()) { - const float targetAge = target.file.getFloat("Age", -1); - const float queryAge = target.file.getFloat("Age", -1); - if ((targetAge != -1) && (queryAge != -1) && (abs(targetAge - queryAge) > Globals->ageDelta)) - return -std::numeric_limits::max(); - } return a * (_compare(target, query) - b); } diff --git a/sdk/openbr_plugin.h b/sdk/openbr_plugin.h index fb7dcc2..371f567 100644 --- a/sdk/openbr_plugin.h +++ b/sdk/openbr_plugin.h @@ -498,14 +498,10 @@ public: /*! * \brief Keys to use when matching templates to automatically determine non-match based on template metadata. */ - Q_PROPERTY(QStringList demographicFilters READ get_demographicFilters WRITE set_demographicFilters RESET reset_demographicFilters) - BR_PROPERTY(QStringList, demographicFilters, QStringList()) - /*! - * \brief Allowable age difference when matching templates. - */ - Q_PROPERTY(float ageDelta READ get_ageDelta WRITE set_ageDelta RESET reset_ageDelta) - BR_PROPERTY(float, ageDelta, std::numeric_limits::max()) + typedef QHash DemographicFilters; + Q_PROPERTY(DemographicFilters demographicFilters READ get_demographicFilters WRITE set_demographicFilters RESET reset_demographicFilters) + BR_PROPERTY(DemographicFilters, demographicFilters, DemographicFilters()) /*! * \brief If \c true a template will be skipped over if its file name already exists in the gallery.