Open Caroljpeg opened 1 year ago
Hi @Caroljpeg , I saw the issue while surfing the web, so please correct me if this isn't what you need.
I assume you will need to combine those emotions in an object to access later with the expression score, you will iterate over the key values using the Object.keys
and ES6 find
method as follows:
let angry = resizedDetectionData.expressions.angry;
let disgusted = resizedDetectionData.expressions.disgusted;
let fearful = resizedDetectionData.expressions.fearful;
let happy = resizedDetectionData.expressions.happy;
let neutral = resizedDetectionData.expressions.neutral;
let sad = resizedDetectionData.expressions.sad;
let surprised = resizedDetectionData.expressions.surprised;
const emotions = {
angry,
disgusted,
fearful,
happy,
neutral,
sad,
surprised
};
const getEmotionByScore = (obj, score) =>
Object.keys(obj).find(key => obj[key] === score);
const score = (Math.max(angry, disgusted, fearful, happy, neutral, sad, surprised));
const emotion = getEmotionByScore(emotions, score);
console.log(emotion);
What do you think about this ?
For an interactive installation I need to start a different function depending on the emotion detected by face-api. This is the code I wrote for the moment: `let angry = resizedDetectionData.expressions.angry; let disgusted = resizedDetectionData.expressions.disgusted; let fearful = resizedDetectionData.expressions.fearful; let happy = resizedDetectionData.expressions.happy; let neutral = resizedDetectionData.expressions.neutral; let sad = resizedDetectionData.expressions.sad; let surprised = resizedDetectionData.expressions.surprised;
let expression = (Math.max(angry, disgusted, fearful, happy, neutral, sad, surprised)); console.log(expression);`
but in this way the console log the value of the highest variable, not its name. Can anyone help me?