2

I am using a JS library for facetracking/emotion detection called CLMtracker.

http://auduno.github.io/clmtrackr/examples/clm_emotiondetection.html

Note: Seems to work best in chrome for those trying to use it.

Is the example I am using, I am wondering how I can access the values for each emotion. For instance, I want check every 10 seconds what the values are and print to console. From this I would also like to compare the values to find the highest and find the emotion that is attached to that. I think I am right in saying that the max() function will give me the highest out of an array?

What I have tried:

I have tried to get emotionData[0].emotion and emotionData[0].value which should print Angry and the value, but it only prints 0. I have also tried the same method with data which does not seem to return anything.

EDIT

emotionData gets me:

however it does not seem to show any update/change as I make my expression change

enter image description here

6
  • When you do console.log(emotionData);, what do you get? Math.max.apply(null,yourArray) needs to be written that way when aplied to an array and not integers. Commented May 18, 2014 at 20:35
  • see Edit for the response. I can access that array of objects, but the values don't seem to move from 0 even as I change my expression to make the numbers change. Commented May 18, 2014 at 20:44
  • I've never used this, but yes, from looking at their code, emotionData contains all possible emotions, not the users' actual emotions. I'm currently searching where this is stored. Commented May 18, 2014 at 20:49
  • Yeh it's my first time delving in to this kind of thing but I am trying to experiment, let me know you if you manage to find anything! Commented May 18, 2014 at 20:56
  • I got it :) I'm posting a detailed answer. Commented May 18, 2014 at 21:04

1 Answer 1

1

ec.meanPredict(ctrack.getCurrentParameters()) returns an object containing all the current scores for all emotions.

To get the current score of "Angry", for example, you would do :

ec.meanPredict(ctrack.getCurrentParameters())[0].value

So, in order to get the current most probable emotion, you could do this :

function getCurrentEmotion()
{
    if(!ec.meanPredict(ctrack.getCurrentParameters())){setTimeout(getCurrentEmotion,1000);return;}
    var currentData = ec.meanPredict(ctrack.getCurrentParameters());
    var currentScores = [];

    //Gather all scores in an array
    for(var i=0;i<currentData.length;i++)
    {
        currentScores.push(currentData[i].value);
    }

    //Get the biggest score
    var max = Math.max.apply(null,currentScores);
    //Calculate its index
    var indexOfScore = currentScores.indexOf(max);
    //Get the associated emotion
    var emotion = currentData[indexOfScore].emotion;
    console.log(emotion);

    //Set up a loop (did not add 'var', to allow stopping it from outside)
    currentEmotionLoop = setTimeout(getCurrentEmotion,3000);
}

To stop the loop at any time, do this :

clearTimeout(currentEmotionLoop);

By the way, the ec variable is declared privately, so in order for this to work, either remove var where it is declared :

var ec = new emotionClassifier();

or write this code in the same file, under the same scope.

Sign up to request clarification or add additional context in comments.

8 Comments

Couple of things, don't you need var i=0? you got ++i instead of i++? Other than that it seems to be working, also are you able to make it perform this check every X amount of time. I know I can use setTimeout() but when I tried to implement it it crashed my browser with 4000+ request in a matter of seconds !!
You're right about var i, I edited it. ++i and i++ work the same. I'll add the setTimeout in a minute.
Aha sorry I wasn't aware of ++i! learn something new everday. Thats great, apart from those issues it seems to work perfectly.
Well technically, there is a difference (See this). But it does not matter on this particular case. Please tell me if the loop works, I did not try it. It should do it every 10 seconds.
I seem to be getting Uncaught TypeError: Cannot read property 'emotion' of undefined . Where in the code did you place this new function? I feel as though I misplaced it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.