Giter VIP home page Giter VIP logo

aind-cv-mimic's Introduction

Project: Mimic Me!

Playing From Your browser

The demonstration application including the debug information from Affectiva’s API calls is seen here;

Demonstration

For a truly special version visit: NYAN Version (Not working on mobile browsers...yet)

m key mutes the music, you're welcome

Overview

This project tracks the faces in a video and identify facial expressions using Affectiva API. We are able to match the expression to a fixed set of emoji and compare them in real-time.

Getting Started

We’ll be using Affectiva’s Emotion-as-a-Service API for this project. Visit their Developer Portal and try out some of the sample apps. Affectiva makes it really easy to extract detailed information about faces in an image or video stream. To get a sense for what information you can obtain, check out the Metrics page.

Serving locally over HTTPS

In order to access the webcam stream, modern browsers require you to serve your web app over HTTPS. To run locally, you will need to general an SSL certificate (this is a one-time step):

  • Open a terminal or command-prompt, and ensure you are inside the AIND-CV-Mimic/ directory.
  • Run the following shell script: generate-pemfile.sh

This creates an SSL certificate file named my-ssl-cert.pem that is used to serve over https.

Now you can launch the server using:

python serve.py

Note: The serve.py script uses Python 3.

Running and implementing the game

Open a web browser and go to: https://localhost:4443/

  • Hit the Start button to initiate face tracking. You may have to give permission for the app to access your webcam.
  • Hit the Stop button to stop tracking and Reset to reset the detector (in case it becomes stuck or unstable).
  • When you’re done, you can shutdown the server by pressing Ctrl+C at the terminal.

Note: Your browser may notify you that your connection is not secure - that is because the SSL certificate you just created is not signed by an SSL Certificate Authority‎. This is okay, because we are using it only as a workaround to access the webcam. You can suppress the warning or choose "Proceed Anyway" to open the page.

Background Tasks

1. Display Feature Points

The API returns an array of feature points from the service. These represent key points on the face. The code uses the HTML5 canvas object and draws a small circle at the point location.

// Draw the detected facial feature points on the image
function drawFeaturePoints(canvas, img, face) {
  // Obtain a 2D context object to draw on the canvas
  var ctx = canvas.getContext('2d');

  // Loop over each feature point in the face
  for (var id in face.featurePoints) {
    var featurePoint = face.featurePoints[id];
      drawPoint(featurePoint.x, featurePoint.y,ctx);
  }
}
function drawPoint(x, y, canvas){
  canvas.beginPath();
  canvas.arc(x, y, 1, 0, 2 * Math.PI, true);
  canvas.stroke();
}

Screenshot

2. Show Dominant Emoji

In addition to feature points and metrics that capture facial expressions and emotions, the Affectiva API also reports back what emoji best represents the current emotional state of a face. This is referred to as the dominant emoji.

The emoji is drawn using a HTML5 fillText call. We fix the size at 48px but track the emoji to the users face. Trial and error found that point[13] in the list was typically the center of the face.

// Draw the dominant emoji on the image
function drawEmoji(canvas, img, face) {
  // Obtain a 2D context object to draw on the canvas
  var ctx = canvas.getContext('2d');

  var emoji = face.emojis.dominantEmoji;

  // Usually its the center
  var featurePoint = face.featurePoints[13];

  if(emoji != 0){
    ctx.font = '48px serif';
    ctx.fillText(emoji, featurePoint.x, featurePoint.y);
  }
}

Screenshot

3. Game

Taking the same metric and adding some game play mechanism you can see how Affectiva works here; NYAN Version

Screenshot

Mobile browser support is not supported on the Affectiva SDK yet

Affectiva Resources

Refer to resources in Affectiva's JS SDK documentation.

Other references:

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. Please refer to Udacity Terms of Service for further information.

aind-cv-mimic's People

Contributors

johncarpenter avatar napratin avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.