-
Notifications
You must be signed in to change notification settings - Fork 0
/
euclidianmetric.cpp
33 lines (26 loc) · 944 Bytes
/
euclidianmetric.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "euclidianmetric.h"
double EuclidianMetric::getDistance(Descriptor &desc1, Descriptor &desc2)
{
if (desc1.size() != desc2.size())
throw std::logic_error("Error: out of bounds!");
double distance = 0;
for (int i = 0; i < desc1.size(); i++)
distance += sqr(desc1[i] - desc2[i]);
return std::sqrt(distance);
}
Descriptor EuclidianMetric::getCentroid(std::vector<FeaturePoint> &vecFeaturePoint, std::vector<int> &vecIdList)
{
if (vecIdList.empty())
throw std::runtime_error("Error: cluster is empty!");
int sizeDesc = vecFeaturePoint[0].descriptor().size();
Descriptor bufValue(sizeDesc);
int countRec = vecIdList.size();
for (int i = 0; i < sizeDesc; i++)
{
double result = 0;
for (int j = 0; j < countRec; j++)
result += vecFeaturePoint[vecIdList[j]].descriptor()[i];
bufValue[i] = result / countRec;
}
return bufValue;
}