Utils.java
2.13 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.viontech.match.util;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
/**
* .
*
* @author 谢明辉
* @version 0.0.1
*/
@Slf4j
@SuppressWarnings("ALL")
public class Utils {
/**
* 将 2110 维的人体特征加权计算得到 2048 维特征数据
*
* @param f1 2110 维的人体特征数据
*
* @return 加权计算后的结果
*/
public static Double[] transferBodyFeature(Double[] f1) {
try {
int featureLen = f1[0].intValue();
int npiece = f1[1].intValue();
Double[] vec1 = Arrays.copyOfRange(f1, 3, 2048 + 3);
Double[] temp = Arrays.copyOfRange(f1, 3 + featureLen + npiece, f1.length);
Double[] wt1 = getWeights(temp);
Double normCoeF1 = 0D;
for (int i = 0; i < 8; i++) {
normCoeF1 += wt1[i] * wt1[i] * f1[3 + 2048 + i];
}
normCoeF1 = 1 / Math.sqrt(normCoeF1);
for (int i = 0; i < 2048; i++) {
vec1[i] = vec1[i] * wt1[i / 256] * normCoeF1;
}
return vec1;
} catch (Throwable e) {
log.error("转换出错", e);
}
return f1;
}
private static Double[] getWeights(Double[] landmarks) {
Double[] wt = new Double[8];
Arrays.fill(wt, 1D);
if (landmarks[15 * 3 + 2] > 0.8 && landmarks[16 * 3 + 2] > 0.8) {
} else if (landmarks[15 * 3 + 2] > 0.8 || landmarks[16 * 3 + 2] > 0.8) {
wt[7] = 0.7;
} else if (landmarks[13 * 3 + 2] > 0.8 && landmarks[14 * 3 + 2] > 0.8) {
wt[7] = 0.2;
wt[3] = 0.7;
} else if (landmarks[13 * 3 + 2] > 0.8 || landmarks[14 * 3 + 2] > 0.8) {
wt[7] = 0.1;
wt[3] = 0.4;
} else if (landmarks[11 * 3 + 2] > 0.7 && landmarks[12 * 3 + 2] > 0.7) {
wt[7] = 0D;
wt[3] = 0.2;
wt[6] = 0.8;
wt[2] = 1.1;
wt[5] = 1.1;
} else {
wt[7] = 0D;
wt[3] = 0D;
wt[6] = 0.3;
wt[2] = 1.2;
wt[5] = 1.4;
}
return wt;
}
}