Identify Faces and Emotions using Microsoft Face API

Facial recognition is one of the key element you would find in a modern designs and implementations. With the advancements of the AI and Machine learning algorithms, it keeps improving day by day to analyze and recognize the people more accurately than ever before. In past, though we’ve seen facial detection and facial recognition scenes in Hollywood movies, it started to become a reality specially general purpose applications in recent past.

You may be a solution designer or architect who works with Healthcare industry, you can implement face detection and identification solution to detect patient faces using CCTV cameras, in order to minimize the risks and incidents. You may be designing a solution for the business processes where public engaging, Financial companies, banks, an public events etc. Even for corporate offices, you can implement a facial recognition solution to identify faces and mark their roles. There may be thousands of use cases where you can implement facial recognition system.

Microsoft Face API has made your job simpler, and accessible by providing a cloud-based service which built by using most advanced face recognition algorithms which you can invoke and get the results more accurately.

Face API has two main functionsFace Detection: Face API detects up to 64 human faces in an image accurately. The image can specify file in bytes or URL.
It detects face location with optional attributes which related to faces like gender, age, pose, head pose, facial hair etc. More details about the API for development click here

Face Recognition
API provides verification against two detected faces or verify from a one detected face to one person object
Some other features of face recognition are finding similar faces: by given target face and set of candidate's faces to search with
face grouping: given one set of unknown faces, and from the Face grouping API automatically divide and group into several disjoint sets. Each set contains similar faces. All the faces in the same group can be considered as those are belongs to the same person.
person identification: face API can be used to detect and identify people based on people database( a people group as above).

I've provided the sample code I used to perform a face detection and emotions identification.

Prerequisites

Microsoft Face API windows SDK

You can install the Face API Windows SDK from Nuget package manager. This is going to be a C# console application. You can select any other template as well. Once you opened open the Nuget Package manager console and type this command.

Once you build the code and run, in the command console will place you to provide the Face Location from your machine to analyze. I tried with 4 different photos in which I downloaded include mine and checked the results along with the input image.

API detected the facial expression and the gender properly in my image.

In this image, it detects accurately that Huge's emotion as anger.

Similar to that in 3rd image emotion as a surprise and other optional features

In this 4th image it detects that she is wearing glasses and she is in happy mode.

This is just a beginning for the Face API. But there is lot hidden gems there we can work with in order to make some advanced applications. Especially people grouping and detect accurately among a group of people in a photo. But, that doesn't mean that this code we start cannot apply to real-world scenarios.

Yes, we can. There are a bunch of applications we can do even with this code. Ex: identify whether employee or students in a class whether happy or not. Specially person behavior over time. Customer satisfaction in a Bank are just a few of them 😊