From bd8be3234f71abec4c54172615dc5679f8a2f2cb Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Thu, 2 Apr 2015 10:25:32 -0400 Subject: [PATCH] Added emd distance --- openbr/plugins/distance/emd.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+), 0 deletions(-) create mode 100644 openbr/plugins/distance/emd.cpp diff --git a/openbr/plugins/distance/emd.cpp b/openbr/plugins/distance/emd.cpp new file mode 100644 index 0000000..71e99b4 --- /dev/null +++ b/openbr/plugins/distance/emd.cpp @@ -0,0 +1,42 @@ +#include +#include + +using namespace cv; + +namespace br +{ + +/*! + * \ingroup distances + * \brief Fuses similarity scores across multiple matrices of compared templates + * \author Scott Klum \cite sklum + * \note Operation: Mean, sum, min, max are supported. + */ +class EMDDistance : public UntrainableDistance +{ + Q_OBJECT + + float compare(const Template &a, const Template &b) const + { + Mat sig_a(a.m().cols, 2, CV_32FC1); + Mat sig_b(b.m().cols, 2, CV_32FC1); + + for (int i=0; i(i,0) = a.m().at(0,i); + sig_a.at(i,1) = i; + } + + for (int i=0; i(i,0) = b.m().at(0,i); + sig_b.at(i,1) = i; + } + + return EMD(sig_a,sig_b,CV_DIST_L2); + } +}; + +BR_REGISTER(Distance, EMDDistance) + +} // namespace br + +#include "distance/emd.moc" -- libgit2 0.21.4