Monday, November 27, 2017

Working with Microsoft Cognitive Services - Emotions

Here is the way by which we can get Emotions of image which contains face and by consuming service of Microsoft Cognitive Service we can detect face along with its emotions.

- All you need for this service to consume is 1) api url 2) Subscription Key
- For this example use image having faces and make sure you pass image convert into byte stream and pass it to service call which will return faces in it and emotions of that faces

Below is the code for this

var client = new HttpClient();

var queryString = HttpUtility.ParseQueryString(string.Empty);
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", Your Subscription Key);

var uri = uri + queryString;

HttpResponseMessage response;
Emotion[] emotionResult = null;

// Request body
byte[] byteData = image stream in bytes;

using (var content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response = await client.PostAsync(uri, content);
return response;
}

For this, please find below links to explore more
(1) Emotion API in C# Tutorial

(2) Emotion API

No comments:

Post a Comment