diff --git a/openbr/plugins/cluster.cpp b/openbr/plugins/cluster.cpp index 14cdb03..3a9b577 100644 --- a/openbr/plugins/cluster.cpp +++ b/openbr/plugins/cluster.cpp @@ -90,11 +90,13 @@ class KNNTransform : public Transform Q_PROPERTY(bool weighted READ get_weighted WRITE set_weighted RESET reset_weighted STORED false) Q_PROPERTY(int numSubjects READ get_numSubjects WRITE set_numSubjects RESET reset_numSubjects STORED false) Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) + Q_PROPERTY(QString outputVariable READ get_outputVariable WRITE set_outputVariable RESET reset_outputVariable STORED false) BR_PROPERTY(int, k, 1) BR_PROPERTY(br::Distance*, distance, NULL) BR_PROPERTY(bool, weighted, false) BR_PROPERTY(int, numSubjects, 1) BR_PROPERTY(QString, inputVariable, "Label") + BR_PROPERTY(QString, outputVariable, "KNN") TemplateList gallery; @@ -123,7 +125,7 @@ class KNNTransform : public Transform sortedScores.removeAt(j); } - dst.file.set("KNN", subjects.size() > 1 ? "[" + subjects.join(",") + "]" : subjects.first()); + dst.file.set(outputVariable, subjects.size() > 1 ? "[" + subjects.join(",") + "]" : subjects.first()); } void store(QDataStream &stream) const diff --git a/openbr/plugins/independent.cpp b/openbr/plugins/independent.cpp index e220d74..00770bf 100644 --- a/openbr/plugins/independent.cpp +++ b/openbr/plugins/independent.cpp @@ -9,7 +9,7 @@ using namespace cv; namespace br { -static TemplateList Downsample(const TemplateList &templates, const Transform *transform) +static TemplateList Downsample(const TemplateList &templates, const Transform *transform, const QString & inputVariable) { // Return early when no downsampling is required if ((transform->classes == std::numeric_limits::max()) && @@ -20,11 +20,11 @@ static TemplateList Downsample(const TemplateList &templates, const Transform *t const bool atLeast = transform->instances < 0; const int instances = abs(transform->instances); - QList allLabels = templates.get("Label"); + QList allLabels = templates.get(inputVariable); QList uniqueLabels = allLabels.toSet().toList(); qSort(uniqueLabels); - QMap counts = templates.countValues("Label", instances != std::numeric_limits::max()); + QMap counts = templates.countValues(inputVariable, instances != std::numeric_limits::max()); if ((instances != std::numeric_limits::max()) && (transform->classes != std::numeric_limits::max())) foreach (const QString & label, counts.keys()) @@ -74,7 +74,9 @@ class IndependentTransform : public MetaTransform { Q_OBJECT Q_PROPERTY(br::Transform* transform READ get_transform WRITE set_transform RESET reset_transform STORED false) + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) BR_PROPERTY(br::Transform*, transform, NULL) + BR_PROPERTY(QString, inputVariable, "Label") QList transforms; @@ -123,7 +125,7 @@ class IndependentTransform : public MetaTransform transforms.append(transform->clone()); for (int i=0; i futures; for (int i=0; i labels = data.indexProperty("Label"); + const QList labels = data.indexProperty(inputVariable); const int dims = m.cols; vector mv, av, bv; diff --git a/openbr/plugins/quality.cpp b/openbr/plugins/quality.cpp index 972fecb..468ef5e 100644 --- a/openbr/plugins/quality.cpp +++ b/openbr/plugins/quality.cpp @@ -19,17 +19,20 @@ class ImpostorUniquenessMeasureTransform : public Transform Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) Q_PROPERTY(double mean READ get_mean WRITE set_mean RESET reset_mean) Q_PROPERTY(double stddev READ get_stddev WRITE set_stddev RESET reset_stddev) + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) BR_PROPERTY(br::Distance*, distance, Distance::make("Dist(L2)", this)) BR_PROPERTY(double, mean, 0) BR_PROPERTY(double, stddev, 1) + BR_PROPERTY(QString, inputVariable, "Label") + TemplateList impostors; float calculateIUM(const Template &probe, const TemplateList &gallery) const { - const QString probeLabel = probe.file.get("Label"); + const QString probeLabel = probe.file.get(inputVariable); TemplateList subset = gallery; for (int j=subset.size()-1; j>=0; j--) - if (subset[j].file.get("Label") == probeLabel) + if (subset[j].file.get(inputVariable) == probeLabel) subset.removeAt(j); QList scores = distance->compare(subset, probe); @@ -151,6 +154,7 @@ class MatchProbabilityDistance : public Distance Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) Q_PROPERTY(bool gaussian READ get_gaussian WRITE set_gaussian RESET reset_gaussian STORED false) Q_PROPERTY(bool crossModality READ get_crossModality WRITE set_crossModality RESET reset_crossModality STORED false) + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) MP mp; @@ -158,7 +162,7 @@ class MatchProbabilityDistance : public Distance { distance->train(src); - const QList labels = src.indexProperty("Label"); + const QList labels = src.indexProperty(inputVariable); QScopedPointer matrixOutput(MatrixOutput::make(FileList(src.size()), FileList(src.size()))); distance->compare(src, src, matrixOutput.data()); @@ -201,6 +205,7 @@ protected: BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) BR_PROPERTY(bool, gaussian, true) BR_PROPERTY(bool, crossModality, false) + BR_PROPERTY(QString, inputVariable, "Label") }; BR_REGISTER(Distance, MatchProbabilityDistance) @@ -217,10 +222,12 @@ class HeatMapDistance : public Distance Q_PROPERTY(bool gaussian READ get_gaussian WRITE set_gaussian RESET reset_gaussian STORED false) Q_PROPERTY(bool crossModality READ get_crossModality WRITE set_crossModality RESET reset_crossModality STORED false) Q_PROPERTY(int step READ get_step WRITE set_step RESET reset_step STORED false) + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) BR_PROPERTY(bool, gaussian, true) BR_PROPERTY(bool, crossModality, false) BR_PROPERTY(int, step, 1) + BR_PROPERTY(QString, inputVariable, "Label") QList mp; @@ -228,7 +235,7 @@ class HeatMapDistance : public Distance { distance->train(src); - const QList labels = src.indexProperty("Label"); + const QList labels = src.indexProperty(inputVariable); QList patches; @@ -309,14 +316,16 @@ class UnitDistance : public Distance Q_PROPERTY(br::Distance *distance READ get_distance WRITE set_distance RESET reset_distance) Q_PROPERTY(float a READ get_a WRITE set_a RESET reset_a) Q_PROPERTY(float b READ get_b WRITE set_b RESET reset_b) + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) BR_PROPERTY(float, a, 1) BR_PROPERTY(float, b, 0) + BR_PROPERTY(QString, inputVariable, "Label") void train(const TemplateList &templates) { const TemplateList samples = templates.mid(0, 2000); - const QList sampleLabels = samples.indexProperty("Label"); + const QList sampleLabels = samples.indexProperty(inputVariable); QScopedPointer matrixOutput(MatrixOutput::make(FileList(samples.size()), FileList(samples.size()))); Distance::compare(samples, samples, matrixOutput.data()); diff --git a/openbr/plugins/quantize.cpp b/openbr/plugins/quantize.cpp index 163da7f..e74513f 100644 --- a/openbr/plugins/quantize.cpp +++ b/openbr/plugins/quantize.cpp @@ -120,6 +120,10 @@ BR_REGISTER(Transform, HistEqQuantizationTransform) class BayesianQuantizationDistance : public Distance { Q_OBJECT + + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) + BR_PROPERTY(QString, inputVariable, "Label") + QVector loglikelihoods; static void computeLogLikelihood(const Mat &data, const QList &labels, float *loglikelihood) @@ -150,7 +154,7 @@ class BayesianQuantizationDistance : public Distance qFatal("Expected sigle matrix templates of type CV_8UC1!"); const Mat data = OpenCVUtils::toMat(src.data()); - const QList templateLabels = src.indexProperty("Label"); + const QList templateLabels = src.indexProperty(inputVariable); loglikelihoods = QVector(data.cols*256, 0); QFutureSynchronizer futures; @@ -343,9 +347,11 @@ class ProductQuantizationTransform : public Transform Q_PROPERTY(int n READ get_n WRITE set_n RESET reset_n STORED false) Q_PROPERTY(br::Distance *distance READ get_distance WRITE set_distance RESET reset_distance STORED false) Q_PROPERTY(bool bayesian READ get_bayesian WRITE set_bayesian RESET reset_bayesian STORED false) + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) BR_PROPERTY(int, n, 2) BR_PROPERTY(br::Distance*, distance, Distance::make("L2", this)) BR_PROPERTY(bool, bayesian, false) + BR_PROPERTY(QString, inputVariable, "Label") quint16 index; QList centers; @@ -474,7 +480,7 @@ private: Mat data = OpenCVUtils::toMat(src.data()); const int step = getStep(data.cols); - const QList labels = src.indexProperty("Label"); + const QList labels = src.indexProperty(inputVariable); Mat &lut = ProductQuantizationLUTs[index]; lut = Mat(getDims(data.cols), 256*(256+1)/2, CV_32FC1); diff --git a/openbr/plugins/quantize2.cpp b/openbr/plugins/quantize2.cpp index d46db1e..8d05523 100644 --- a/openbr/plugins/quantize2.cpp +++ b/openbr/plugins/quantize2.cpp @@ -19,6 +19,10 @@ namespace br class BayesianQuantizationTransform : public Transform { Q_OBJECT + + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) + BR_PROPERTY(QString, inputVariable, "Label") + QVector thresholds; static void computeThresholdsRecursive(const QVector &cumulativeGenuines, const QVector &cumulativeImpostors, @@ -77,7 +81,7 @@ class BayesianQuantizationTransform : public Transform void train(const TemplateList &src) { const Mat data = OpenCVUtils::toMat(src.data()); - const QList labels = src.indexProperty("Label"); + const QList labels = src.indexProperty(inputVariable); thresholds = QVector(256*data.cols);