Before reading this article, please go through the following articles.
- Introduction To Universal Windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015
- How
To Create Microsoft Cognitive Service Emotion API On Azure Portal
- Cognitive Service Face API, Using UWP With Azure, XAML And C#
Microsoft Cognitive Services let you build apps with powerful algorithms, using just a few lines of code. They work across devices and platforms (such as iOS, Android, and Windows), keep improving, and are easy to set up.
The emotions detected are anger, contempt, disgust, fear, happiness, neutral, sadness, and surprise. These emotions are understood to be cross-culturally and universally communicated with particular facial expressions.
Reading this article, you can learn how to create Cognitive Service Emotion API in Universal Windows Apps development with Azure, XAML, and Visual C#. Here, input is a captured image and Emotion API returns different emotions like anger, contempt, disgust, fear, happiness, neutral, sadness, and surprise.
The following important tools are required for developing UWP.
- Windows 10 (Recommended).
- Visual Studio 2015 Community Edition (It is a free software available online).
- Emotion API Key (How To Create Microsoft Cognitive Service Emotion API On Azure Portals).
Now, we can discuss step by step app development.
Step 1
Open Visual Studio 2015. Go to Start -> New Project-> select Universal (under Visual C# -> Windows) -> Blank App -> give your app a suitable name (UWPCoginitiveEmotion) -> OK.

After choosing the target and minimum platform versions that your app will support, the Project creates App.xaml and MainPage.xaml.

Add TextBlock control and change the name and text property for the title.

Step 2
Add Image control and set the name property for storing the captured image.

Add a Button control and set the name for taking a photo from stream to image control.

Add a Button control and set the name as Get Emotions.

Add the Click event method for both the button controls.

Add a Textblock control and set the name and text properties for Emotion result.

Step 3
Open (double click) the file MainPage.xaml in the Solution Explorer and add the following references in the project.
- Microsoft.ProjectOxford.Face
- Newtonsoft.Json
For adding Microsoft.ProjectOxford.Face Reference, right click your project (UWPCoginitiveEmotion) and select "Manage NuGet Packages".

Choose "Browse" and search Microsoft.ProjectOxford.Face. Select the package and install it.

Reference is added to your project.

For adding Newtonsoft.Json Reference, choose browse and search Newtonsoft.Json, select the package and install it.

Reference added to your project.

Note
Automatically, the following code will be generated in XAML code view, while we are done in the design view.
- <Page x:Class="UWPCoginitiveEmotion.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:UWPCoginitiveEmotion" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <TextBlock x:Name="tblTitle" HorizontalAlignment="Left" Margin="255,98,0,0" TextWrapping="Wrap" Text="UWP Cognitive Service Emotion API Demo" VerticalAlignment="Top" FontSize="36" FontWeight="Bold" />
- <Image x:Name="imgEmotion" HorizontalAlignment="Left" Height="304" Margin="408,224,0,0" VerticalAlignment="Top" Width="310" />
- <Button x:Name="btnTakePhoto" Content="Take Photo" HorizontalAlignment="Left" Margin="172,548,0,0" VerticalAlignment="Top" FontSize="20" FontWeight="Bold" Click="btnTakePhoto_Click" />
- <Button x:Name="btnEmotions" Content="Get Emotions" HorizontalAlignment="Left" Margin="810,548,0,0" VerticalAlignment="Top" Height="39" Width="227" FontSize="20" FontWeight="Bold" Click="btnEmotions_Click" />
- </Grid>
- </Page>





Vijayaragavan SPosted Apr 18, 2017, 12:21 PM
Hi... Refer Step 2, last stage
Rky MishraPosted Apr 18, 2017, 12:07 PM
Its say tblEmotion doesn't exits. What can be done?
Suketu NayakPosted Oct 24, 2016, 6:39 AM
Excellent
Prasanna MuraliPosted Oct 22, 2016, 11:45 AM
Nice post
Karthikeyan KPosted Oct 22, 2016, 6:38 AM
Nice Share...