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

Dan W
  • 365
  • 1
  • 4
  • 20
  • 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. – blex May 18 '14 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. – Dan W May 18 '14 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. – blex May 18 '14 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! – Dan W May 18 '14 at 20:56
  • I got it :) I'm posting a detailed answer. – blex May 18 '14 at 21:04
  • It works! Haha I didn't think it would, but I get the right value everytime. By the way, this plugin is amazing! I had never heard of it. – blex May 18 '14 at 21:20

1 Answers1

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.

blex
  • 24,941
  • 5
  • 39
  • 72
  • 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 !! – Dan W May 18 '14 at 21:27
  • You're right about `var i`, I edited it. `++i` and `i++` work the same. I'll add the setTimeout in a minute. – blex May 18 '14 at 21:30
  • Aha sorry I wasn't aware of ++i! learn something new everday. Thats great, apart from those issues it seems to work perfectly. – Dan W May 18 '14 at 21:34
  • Well technically, there is a difference ([See this](http://stackoverflow.com/questions/24853/what-is-the-difference-between-i-and-i)). 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. – blex May 18 '14 at 21:37
  • 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. – Dan W May 18 '14 at 21:40
  • I actually did not download the files, I worked directly on the site you provided, in my console. On the demo site, you would place it in the index.html file. – blex May 18 '14 at 21:42
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/53920/discussion-between-blex-and-dan-w) – blex May 18 '14 at 21:43
  • I have it within the Index.html file, in that – Dan W May 18 '14 at 21:45