The Cloud Power


Using Microsoft Cognitive Services Face API

January 6, 2017 Cognitive Services 0

Sharing is caring!

In this article you will learn how to create a simple desktop WPF Application that uses the Face API to detect the no of faces in the image and mark the faces in images.

Cognitive Services Face API


What we will learn?

  1. How to subscribe Face API
  2. Generate Face API Subscription Key.
  3. Create new WPF Application (Classic Desktop).
  4. Configuring Face API library.
  5. Upload Image and detect no of Faces in Image.

Subscribe Face API

Step 1 : Go to

Signup with your email address to subscribe Face API in Microsoft Cognitive Services.

Step 2 : Once you are logged in, navigate to Get Started for Free

Get started for free


Step 3 : Now choose face API to subscribe Microsoft Cognitive Services Face API. Proceed further with Subscribe

Subscribe Face API

Step 4 : Now Generate your Subscription key

My free subscriptions

Create Application (Classic Desktop)

Step 1 : Create new Project as Visual C# > Windows Desktop > WPF Application.

New Project to demo Face API


Step 2 : Name the project as FaceDetectionDemo and click OK

You will be able to see following screen.

MainWindow at a glance


Step 3 : Now we need to reference Newtonsoft.Json in our application.

– For this Right click on Project and select Manage Nuget Package

Manage Nuget Package


Browse for Newtonsoft.Json and install

Install Newtonsoft.Json


Again browse for Microsoft.ProjectOxford.Face and Install

Adding Microsoft.ProjectOxford.Face


Adding File Browser to Upload Image.

Step 1 : Add a button on MainWindow.xaml using designer or code. Here I prefer adding button using code.

Replace <Grid></Grid> with following lines of code

<Grid x:Name=”BackPanel”>

<Label x:Name=”Label” FontStretch=”Normal” Margin=”0,0,0,0″ Content=”Please Upload Image to find no of Faces in Image” />

<Image x:Name=”FacePhoto” Stretch=”Uniform” Margin=”0,0,0,30″/>

<Button x:Name=”BrowseButton” Margin=”20,5″ Height=”20″ Background=”Bisque”

VerticalAlignment=”Bottom” Content=”Browse Image”



mainWindow Designer Code


Step 2 : Adding codes to upload image and detect faces.

Now go to MainWindow.xaml.cs

Add this using directive to the beginning of the file:

using Microsoft.ProjectOxford.Face;

using Microsoft.ProjectOxford.Face.Contract;

Add References to MainWindow


Also add following line of code to MainWindows class as:

Invoking IFace Service Client

Add following lines of codes to Click event of Browse Button.

Add a new awaitable function named UploadAndDetectFaces() accepting imageFilePath as object parameter.

Upload and Detect Faces

Application Execution

Step 1 : Build the Application and run.

Step 2 : Browse Image

Step 3 : See Result

You can use Microsoft Cognitive Servies Face API to Detect faces.
You may also like:


Leave a Reply

Skip to toolbar