diff --git a/openbr/core/common.h b/openbr/core/common.h index 09c171e..056dbaa 100644 --- a/openbr/core/common.h +++ b/openbr/core/common.h @@ -116,15 +116,24 @@ T Max(const QList &vals) } /*! + * \brief Returns the sum of a vector of values. + */ +template class V, typename T> +double Sum(const V &vals) +{ + double sum = 0; + foreach (T val, vals) sum += val; + return sum; +} + +/*! * \brief Returns the mean and standard deviation of a vector of values. */ template class V, typename T> double Mean(const V &vals) { if (vals.isEmpty()) return 0; - double sum = 0; - foreach (T val, vals) sum += val; - return sum / vals.size(); + return Sum(vals) / vals.size(); } /*! diff --git a/openbr/plugins/turk.cpp b/openbr/plugins/turk.cpp index 6f17616..c210ff9 100644 --- a/openbr/plugins/turk.cpp +++ b/openbr/plugins/turk.cpp @@ -1,4 +1,5 @@ #include "openbr_internal.h" +#include "openbr/core/common.h" #include "openbr/core/qtutils.h" namespace br @@ -12,6 +13,10 @@ namespace br class turkGallery : public Gallery { Q_OBJECT + Q_PROPERTY(bool flat READ get_flat WRITE set_flat RESET reset_flat STORED false) + Q_PROPERTY(bool normalize READ get_normalize WRITE set_normalize RESET reset_normalize STORED false) + BR_PROPERTY(bool, flat, false) + BR_PROPERTY(bool, normalize, false) struct Attribute : public QStringList { @@ -23,6 +28,23 @@ class turkGallery : public Gallery if (i != -1) append(str.mid(i+1, str.length()-i-2).split(",")); } + + Attribute normalized() const + { + bool ok; + QList values; + foreach (const QString &value, *this) { + values.append(value.toFloat(&ok)); + if (!ok) + qFatal("Can't normalize non-numeric vector!"); + } + + Attribute normal(name); + const float sum = Common::Sum(values); + for (int i=0; i categoryMap; - for (int j=0; j categoryMap; + for (int j=0; j