Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container" id="container">
  <div class="video">
    <video id="videoel" class="video__player" width="400" height="300" preload="auto" loop playsinline autoplay>
    </video>
    <canvas class="video__overlay" id="overlay" width="400" height="300"></canvas>
  </div>
</div>

<div class="emotion" id="emotion_container">
  <div class="emotion__icons" id="emotion_icons">
    <img class="emotion_icon" id="icon1" src="https://www.auduno.com/clmtrackr/examples/media/icon_angry.png">
    <img class="emotion_icon" id="icon2" src="https://www.auduno.com/clmtrackr/examples/media/icon_sad.png">
    <img class="emotion_icon" id="icon3" src="https://www.auduno.com/clmtrackr/examples/media/icon_surprised.png">
    <img class="emotion_icon" id="icon4" src="https://www.auduno.com/clmtrackr/examples/media/icon_happy.png">
  </div>
  <div class="emotion__chart" id='emotion_chart'></div>
</div>

<input class="start" type="button" value="wait, loading video" disabled="disabled" onclick="startVideo()" id="startbutton" />
              
            
!

CSS

              
                body
  margin: 0
  
.container
  position : relative
  width : 100%
  
#overlay 
  position: absolute
  top: 0px
  left: 0px
  transform : scaleX(-1)

#videoel
  transform : scaleX(-1)
  
.video
  width: 55%
  margin: 0 auto
  position: relative
  overflow: hidden
  &:before
    content: ""
    padding-bottom: 75% //4:3
    display: block
  &__player, &__overlay
    position: absolute
    top: 0px
    left: 0px
    width: 100%
    height: 100%

#content
  margin-top : 50px
  margin-left : auto
  margin-right : auto
  max-width: 600px

.start
  position: fixed
  top: 0px
  right: 0px
  width: 200px
  height: 200px
  border-radius: 50%
  background: red
  color: white
  font-size: 30px
  
.emotion
  position: fixed
  bottom: 0px
  left: 0px
  width: 100%
  text-align: center
  &__chart 
    width: 100%
    svg
      width: 100%
  &__icons
    float: left
      
.emotion_icon 
  width : 40px
  height : 40px
  margin-top: 5px
  margin-left : 35px

#icon1, #icon2, #icon3, #icon4, #icon5, #icon6
  visibility : hidden

/* d3 */
.bar
  fill : steelblue
  fill-opacity : .9

              
            
!

JS

              
                var vid = document.getElementById('videoel');
var vid_width = vid.width;
var vid_height = vid.height;
var overlay = document.getElementById('overlay');
var overlayCC = overlay.getContext('2d');

/********** check and set up video/webcam **********/

function enablestart() {
  var startbutton = document.getElementById('startbutton');
  startbutton.value = "start";
  startbutton.disabled = null;
}

function adjustVideoProportions() {
  // resize overlay and video if proportions are different
  // keep same height, just change width
  var proportion = vid.videoWidth/vid.videoHeight;
  vid_width = Math.round(vid_height * proportion);
  vid.width = vid_width;
  overlay.width = vid_width;
}

function gumSuccess( stream ) {
  // add camera stream if getUserMedia succeeded
  if ("srcObject" in vid) {
    vid.srcObject = stream;
  } else {
    vid.src = (window.URL && window.URL.createObjectURL(stream));
  }
  vid.onloadedmetadata = function() {
    adjustVideoProportions();
    vid.play();
  }
  vid.onresize = function() {
    adjustVideoProportions();
    if (trackingStarted) {
      ctrack.stop();
      ctrack.reset();
      ctrack.start(vid);
    }
  }
}

function gumFail() {
  alert("There was some problem trying to fetch video from your webcam. If you have a webcam, please make sure to accept when the browser asks for access to your webcam.");
}

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL || window.msURL || window.mozURL;

// check for camerasupport
if (navigator.mediaDevices) {
  navigator.mediaDevices.getUserMedia({video : true}).then(gumSuccess).catch(gumFail);
} else if (navigator.getUserMedia) {
  navigator.getUserMedia({video : true}, gumSuccess, gumFail);
} else {
  alert("This demo depends on getUserMedia, which your browser does not seem to support. :(");
}

vid.addEventListener('canplay', enablestart, false);

/*********** setup of emotion detection *************/

// set eigenvector 9 and 11 to not be regularized. This is to better detect motion of the eyebrows
pModel.shapeModel.nonRegularizedVectors.push(9);
pModel.shapeModel.nonRegularizedVectors.push(11);

var ctrack = new clm.tracker({useWebGL : true});
ctrack.init(pModel);
var trackingStarted = false;

function startVideo() {
  // start video
  vid.play();
  // start tracking
  ctrack.start(vid);
  trackingStarted = true;
  // start loop to draw face
  drawLoop();
}

function drawLoop() {
  requestAnimFrame(drawLoop);
  overlayCC.clearRect(0, 0, vid_width, vid_height);
  //psrElement.innerHTML = "score :" + ctrack.getScore().toFixed(4);
  if (ctrack.getCurrentPosition()) {
    ctrack.draw(overlay);
  }
  var cp = ctrack.getCurrentParameters();

  var er = ec.meanPredict(cp);
  if (er) {
    updateData(er);
    for (var i = 0;i < er.length;i++) {
      if (er[i].value > 0.4) {
        document.getElementById('icon'+(i+1)).style.visibility = 'visible';
      } else {
        document.getElementById('icon'+(i+1)).style.visibility = 'hidden';
      }
    }
  }
}

delete emotionModel['disgusted'];
delete emotionModel['fear'];
var ec = new emotionClassifier();
ec.init(emotionModel);
var emotionData = ec.getBlank();

/************ d3 code for barchart *****************/

var margin = {top : 20, right : 20, bottom : 10, left : 40},
    width = 400 - margin.left - margin.right,
    height = 100 - margin.top - margin.bottom;

var barWidth = 30;

var formatPercent = d3.format(".0%");

var x = d3.scale.linear()
.domain([0, ec.getEmotions().length]).range([margin.left, width+margin.left]);

var y = d3.scale.linear()
.domain([0,1]).range([0, height]);

var svg = d3.select("#emotion_chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)

svg.selectAll("rect").
data(emotionData).
enter().
append("svg:rect").
attr("x", function(datum, index) { return x(index); }).
attr("y", function(datum) { return height - y(datum.value); }).
attr("height", function(datum) { return y(datum.value); }).
attr("width", barWidth).
attr("fill", "#2d578b");

svg.selectAll("text.labels").
data(emotionData).
enter().
append("svg:text").
attr("x", function(datum, index) { return x(index) + barWidth; }).
attr("y", function(datum) { return height - y(datum.value); }).
attr("dx", -barWidth/2).
attr("dy", "1.2em").
attr("text-anchor", "middle").
text(function(datum) { return datum.value;}).
attr("fill", "white").
attr("class", "labels");

svg.selectAll("text.yAxis").
data(emotionData).
enter().append("svg:text").
attr("x", function(datum, index) { return x(index) + barWidth; }).
attr("y", height).
attr("dx", -barWidth/2).
attr("text-anchor", "middle").
attr("style", "font-size: 20px").
text(function(datum) { return datum.emotion;}).
attr("transform", "translate(0, 18)").
attr("class", "yAxis");

function updateData(data) {
  // update
  var rects = svg.selectAll("rect")
  .data(data)
  .attr("y", function(datum) { return height - y(datum.value); })
  .attr("height", function(datum) { return y(datum.value); });
  var texts = svg.selectAll("text.labels")
  .data(data)
  .attr("y", function(datum) { return height - y(datum.value); })
  .text(function(datum) { return datum.value.toFixed(1);});

  // enter
  rects.enter().append("svg:rect");
  texts.enter().append("svg:text");

  // exit
  rects.exit().remove();
  texts.exit().remove();
}

/******** stats ********/

// stats = new Stats();
// stats.domElement.style.position = 'absolute';
// stats.domElement.style.top = '0px';
// document.getElementById('container').appendChild( stats.domElement );

// // update stats on every iteration
// document.addEventListener('clmtrackrIteration', function(event) {
//   stats.update();
// }, false);
              
            
!
999px

Console