Skip to content
Snippets Groups Projects
Commit bac6f42a authored by D1oStar's avatar D1oStar
Browse files

distance update

parent ef1c27c5
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,10 @@ public:
return std::visit(AnyGet{}, input);
}
static float e_dist(feature_t* F1, feature_t* F2) { return *F1 - *F2; }
static float e_dist(feature_t* F1, feature_t* F2)
{
return fabs(* F1 - *F2);
}
};
class FeatureVector : public Feature
......
#include "features.h"
using namespace pmp;
using pmp::Scalar;
namespace mmr {
Scalar FeatureVector::distance(Histogram& h1, Histogram& h2)
{
Scalar w1[10], w2[10];
std::copy(h1.histogram.begin(), h1.histogram.end(), w1);
std::copy(h2.histogram.begin(), h2.histogram.end(), w2);
feature_t f1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
f2[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
signature_t s1 = {10, f1, w1}, s2 = {10, f2, w2};
std::vector<float>::size_type N1 = h1.histogram.size();
std::vector<float>::size_type N2 = h2.histogram.size();
feature_t *f1 = new feature_t[N1], *f2 = new feature_t[N2];
Scalar *w1 = new Scalar[N1], *w2 = new Scalar[N2];
int i = 0;
for (std::vector<float>::iterator iter = h1.histogram.begin();
iter != h1.histogram.end(); ++iter, ++i)
{
f1[i] = i;
w1[i] = h1.histogram[*iter];
}
i = 0;
for (std::vector<float>::iterator iter = h1.histogram.begin();
iter != h2.histogram.end(); ++iter, ++i)
{
f2[i] = i;
w2[i] = h2.histogram[*iter];
}
signature_t s1 = {N1, f1, w1}, s2 = {N2, f2, w2};
Scalar d = emd(&s1, &s2, Feature::e_dist, 0, 0);
return d;
}
......@@ -21,15 +33,15 @@ Scalar FeatureVector::distance(std::map<std::string, Scalar>& data1,
std::map<std::string, Scalar>& data2,
std::vector<std::string>& index)
{
Scalar d(0.f);
Eigen::VectorXf f1, f2;
for (auto &i : index)
{
auto iter = data1.find(i);
if (iter == data1.end() || iter == data2.end())
continue;
Scalar delta = data1[i] - data2[i];
d += delta * delta;
f1 << f1, Scalar(data1[i]);
f2 << f2, Scalar(data2[i]);
}
return sqrtf(d);
return (f1 - f2).norm();
}
} // namespace mmr
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment