-
Notifications
You must be signed in to change notification settings - Fork 5
/
SuperContourInterpolator.java
47 lines (37 loc) · 1.64 KB
/
SuperContourInterpolator.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.genericsystem.cv.application;
import java.util.List;
public class SuperContourInterpolator {
private final double pow;
private List<SuperContour> superContours;
private double hCoef; // coefficient pour l'angle horizontal
private double vCoef; // coefficient pour l'angle vertical
private double sumHCoefs; // somme des coefficients pour l'angle horizontal
private double sumVCoefs;
private double hAngle; // angle horizontal
private double vAngle; // angle vertical
public SuperContourInterpolator(List<SuperContour> superContours, double pow) {
this.superContours = superContours;
this.pow = pow;
}
private double squaredEuclidianDistance(double x, double y, SuperContour sc) { // distance euclidienne au carré
double result = Math.pow(x - sc.center.x, 2) + Math.pow(y - sc.center.y, 2);
double minDist = 10;
return result >= Math.pow(minDist, 2) ? result : Math.pow(minDist, 2);
}
public double[] interpolate(double x, double y) { // retourne les angles horizontal et vertical interpolés
sumHCoefs = 0; // somme des coefficients pour l'angle horizontal
sumVCoefs = 0;
hAngle = 0; // angle horizontal
vAngle = 0;
superContours.forEach(sc -> {
double geoCoef = Math.pow(1 / (squaredEuclidianDistance(x, y, sc) + 0.00001), pow / 2); // on ajoute un epsilon pour éviter les divisions par 0
hCoef = geoCoef * sc.dx; // la largeur comme indice de confiance dans le coefficient
hAngle += hCoef * sc.angle;
vCoef = geoCoef * sc.dx;// * indice de confiance dy ?
vAngle += vCoef * sc.vertical;
sumHCoefs += hCoef;
sumVCoefs += vCoef;
});
return new double[] { hAngle / sumHCoefs, vAngle / sumVCoefs };
}
}