Find real Emotions using Emotion API

In this article, I'm going to guide you how to work with the Emotion API in Microsoft Cognitive Services. This uses more advanced machine learning algorithms to find emotions from a real image. So this has a huge collection of trained images with emotions of anger, contempt, disgust, fear, happiness, neutral, sadness, surprise.

If the image contains more than one person, it will detect every person in the image with the position and the emotions.

This is a sample response. So this man in a happy mood. Because the confident level (score) of the happy is the highest out of all.

 {
    "faceRectangle": {
      "top": 114,
      "left": 212,
      "width": 65,
      "height": 65
    },
    "scores": {
      "anger": 1.0570484E-08,
      "contempt": 1.52679547E-09,
      "disgust": 1.60232943E-07,
      "fear": 6.00660363E-12,
      "happiness": 0.9999998,
      "neutral": 9.449728E-09,
      "sadness": 1.23025981E-08,
      "surprise": 9.91396E-10
    }
  }

For the usage, you will need emotion API key. So you can generate a free API key from here: API Key Free. Or if you have Azure account, you can get Emotion API key from the portal.

Here is the GitHub repository of sample c# Emotion API usage: GitHub Repo

In here you have to provide the emotion API key in program.cs file as below,

In the GitHub repo, you need to add a subscription key. For that, you can have a trial subscription key from here: https://azure.microsoft.com/en-gb/try/cognitive-services/?api=emotion-api

And when you look on the GitHub repository, you just need to pass an image path from your local device with an active internet connection. So it will return a JSON result.

In the next blog, I will describe how to analyze real-time video with emotions.

In case of any issue, feel free to comment below.

References: Introduction to Cognitive Services