diff --git a/openbr/plugins/distance.cpp b/openbr/plugins/distance.cpp index 8781197..7f0cf71 100644 --- a/openbr/plugins/distance.cpp +++ b/openbr/plugins/distance.cpp @@ -298,6 +298,33 @@ class IdenticalDistance : public Distance BR_REGISTER(Distance, IdenticalDistance) -} // namespace br +/*! + * \ingroup distances + * \brief Online distance metric to attenuate match scores across multiple frames + * \author Brendan klare \cite bklare + */ +class OnlineDistance : public Distance +{ + Q_OBJECT + Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) + Q_PROPERTY(float alpha READ get_alpha WRITE set_alpha RESET reset_alpha STORED false) + BR_PROPERTY(br::Distance*, distance, NULL) + BR_PROPERTY(float, alpha, 0.1f); + + mutable QHash scoreHash; + mutable QMutex mutex; + + float compare(const Template &target, const Template &query) const + { + float currentScore = distance->compare(target, query); + + QMutexLocker mutexLocker(&mutex); + return scoreHash[target.file.name] = (1.0- alpha) * scoreHash[target.file.name] + alpha * currentScore; + } +}; + +BR_REGISTER(Distance, OnlineDistance) + +} // namespace br #include "distance.moc" diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index f872f1a..4ae217a 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -35,6 +35,7 @@ class OpenTransform : public UntrainableMetaTransform void project(const Template &src, Template &dst) const { + if (!src.isEmpty()) { dst = src; return; } if (Globals->verbose) qDebug("Opening %s", qPrintable(src.file.flat())); dst.file = src.file; foreach (const File &file, src.file.split()) { diff --git a/openbr/plugins/pp5.cpp b/openbr/plugins/pp5.cpp index e79ee92..658a0d8 100644 --- a/openbr/plugins/pp5.cpp +++ b/openbr/plugins/pp5.cpp @@ -305,10 +305,14 @@ class PP5CompareDistance : public Distance float compare(const Template &target, const Template &query) const { - (void) target; - (void) query; - qFatal("Compare single templates should never be called!"); - return 0; + TemplateList targetList; + targetList.append(target); + TemplateList queryList; + queryList.append(query); + MatrixOutput *score = MatrixOutput::make(targetList.files(), queryList.files()); + compare(targetList, queryList, score); + return score->data.at(0); + } void compare(const TemplateList &target, const TemplateList &query, Output *output) const