Commit bd8be3234f71abec4c54172615dc5679f8a2f2cb
1 parent
eaf723c9
Added emd distance
Showing
1 changed file
with
42 additions
and
0 deletions
openbr/plugins/distance/emd.cpp
0 → 100644
| 1 | +#include <openbr/plugins/openbr_internal.h> | ||
| 2 | +#include <opencv2/imgproc/imgproc.hpp> | ||
| 3 | + | ||
| 4 | +using namespace cv; | ||
| 5 | + | ||
| 6 | +namespace br | ||
| 7 | +{ | ||
| 8 | + | ||
| 9 | +/*! | ||
| 10 | + * \ingroup distances | ||
| 11 | + * \brief Fuses similarity scores across multiple matrices of compared templates | ||
| 12 | + * \author Scott Klum \cite sklum | ||
| 13 | + * \note Operation: Mean, sum, min, max are supported. | ||
| 14 | + */ | ||
| 15 | +class EMDDistance : public UntrainableDistance | ||
| 16 | +{ | ||
| 17 | + Q_OBJECT | ||
| 18 | + | ||
| 19 | + float compare(const Template &a, const Template &b) const | ||
| 20 | + { | ||
| 21 | + Mat sig_a(a.m().cols, 2, CV_32FC1); | ||
| 22 | + Mat sig_b(b.m().cols, 2, CV_32FC1); | ||
| 23 | + | ||
| 24 | + for (int i=0; i<a.m().cols; i++) { | ||
| 25 | + sig_a.at<float>(i,0) = a.m().at<float>(0,i); | ||
| 26 | + sig_a.at<float>(i,1) = i; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + for (int i=0; i<b.m().cols; i++) { | ||
| 30 | + sig_b.at<float>(i,0) = b.m().at<float>(0,i); | ||
| 31 | + sig_b.at<float>(i,1) = i; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + return EMD(sig_a,sig_b,CV_DIST_L2); | ||
| 35 | + } | ||
| 36 | +}; | ||
| 37 | + | ||
| 38 | +BR_REGISTER(Distance, EMDDistance) | ||
| 39 | + | ||
| 40 | +} // namespace br | ||
| 41 | + | ||
| 42 | +#include "distance/emd.moc" |