Commit 28ac05ec7ed784cf5d69d8367cba79b6d1d5c022
1 parent
970b3bc9
new API for specifying demographic filters
Showing
2 changed files
with
8 additions
and
21 deletions
sdk/openbr_plugin.cpp
| ... | ... | @@ -1315,22 +1315,13 @@ void Distance::compare(const TemplateList &target, const TemplateList &query, Ou |
| 1315 | 1315 | |
| 1316 | 1316 | float Distance::compare(const Template &target, const Template &query) const |
| 1317 | 1317 | { |
| 1318 | - if (!Globals->demographicFilters.isEmpty()) { | |
| 1319 | - // The if statement is a faster check then iterating over an empty list of filters | |
| 1320 | - foreach (const QString &filter, Globals->demographicFilters) { | |
| 1318 | + if (!Globals->demographicFilters.isEmpty()) // If statement is faster than iterating over an empty list of filters | |
| 1319 | + foreach (const QString &filter, Globals->demographicFilters.keys()) { | |
| 1321 | 1320 | const QString targetMetadata = target.file.getString(filter, ""); |
| 1322 | - const QString queryMetadata = query.file.getString(filter, ""); | |
| 1323 | - if (targetMetadata.isEmpty() || queryMetadata.isEmpty()) continue; | |
| 1324 | - if (targetMetadata != queryMetadata) return -std::numeric_limits<float>::max(); | |
| 1321 | + if (!targetMetadata.isEmpty() && | |
| 1322 | + (Globals->demographicFilters[filter].indexIn(targetMetadata) == -1)) | |
| 1323 | + return -std::numeric_limits<float>::max(); | |
| 1325 | 1324 | } |
| 1326 | - } | |
| 1327 | - | |
| 1328 | - if (Globals->ageDelta < std::numeric_limits<float>::max()) { | |
| 1329 | - const float targetAge = target.file.getFloat("Age", -1); | |
| 1330 | - const float queryAge = target.file.getFloat("Age", -1); | |
| 1331 | - if ((targetAge != -1) && (queryAge != -1) && (abs(targetAge - queryAge) > Globals->ageDelta)) | |
| 1332 | - return -std::numeric_limits<float>::max(); | |
| 1333 | - } | |
| 1334 | 1325 | |
| 1335 | 1326 | return a * (_compare(target, query) - b); |
| 1336 | 1327 | } | ... | ... |
sdk/openbr_plugin.h
| ... | ... | @@ -498,14 +498,10 @@ public: |
| 498 | 498 | /*! |
| 499 | 499 | * \brief Keys to use when matching templates to automatically determine non-match based on template metadata. |
| 500 | 500 | */ |
| 501 | - Q_PROPERTY(QStringList demographicFilters READ get_demographicFilters WRITE set_demographicFilters RESET reset_demographicFilters) | |
| 502 | - BR_PROPERTY(QStringList, demographicFilters, QStringList()) | |
| 503 | 501 | |
| 504 | - /*! | |
| 505 | - * \brief Allowable age difference when matching templates. | |
| 506 | - */ | |
| 507 | - Q_PROPERTY(float ageDelta READ get_ageDelta WRITE set_ageDelta RESET reset_ageDelta) | |
| 508 | - BR_PROPERTY(float, ageDelta, std::numeric_limits<float>::max()) | |
| 502 | + typedef QHash<QString,QRegExp> DemographicFilters; | |
| 503 | + Q_PROPERTY(DemographicFilters demographicFilters READ get_demographicFilters WRITE set_demographicFilters RESET reset_demographicFilters) | |
| 504 | + BR_PROPERTY(DemographicFilters, demographicFilters, DemographicFilters()) | |
| 509 | 505 | |
| 510 | 506 | /*! |
| 511 | 507 | * \brief If \c true a template will be skipped over if its file name already exists in the gallery. | ... | ... |