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

Tuesday, January 17, 2017

Apply Template to Kendo Grid Dynamically

Here is some code which will show you how you can apply template for kendo grid view.

(1) For this post, i assume that you have kendo grid with datasource is already applied and you only need to apply template dynamically.

(2) while initializing kendo grid, give your name of the template like below
$('#grid').kendoGrid({
....
rowTemplate: kendo.template($("#template").html()),
....
});

your template "template" will be placed at your html view.
- so for this, whenever your page get load it will automatically bind this template for your individual item
- for this view, if you want to show only template not column title then mark "visible:false" or "hidden:true" or both in you columns so it will just hide your column title on top and show only the item template for each item.

(3) to change your template, find event wherever you want to apply another template and in that event apply below code

var _grid = $('#grid').data('kendoGrid');
_grid.options.rowTemplate = kendo.template($("#othertemplate").html());
_grid.refresh();


(4) so, wherever you want to apply another template just find grid and apply template then refresh grid will reflect your grid with new template applied on it.