gx
chenyc
2025-02-12 ea42ff3ebee1eeb3fb29423aa848a249441db81c
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
export const FACE_EXPRESSION_LABELS = ['neutral', 'happy', 'sad', 'angry', 'fearful', 'disgusted', 'surprised'];
 
export class FaceExpressions {
  public neutral = 0;
  public happy = 0;
  public sad = 0;
  public angry = 0;
  public fearful = 0;
  public disgusted = 0;
  public surprised = 0;
 
  constructor(probabilities: number[] | Float32Array) {
    if (probabilities.length !== 7) {
      throw new Error(`FaceExpressions.constructor - expected probabilities.length to be 7, have: ${probabilities.length}`);
    }
 
    FACE_EXPRESSION_LABELS.forEach((expression, idx) => {
      this[expression] = probabilities[idx];
    });
  }
 
  asSortedArray() {
    return FACE_EXPRESSION_LABELS
      .map((expression) => ({ expression, probability: this[expression] as number }))
      .sort((e0, e1) => e1.probability - e0.probability);
  }
}