Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FaceBot: ServicioFace.cs
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ProjectOxford.Face;
using Microsoft.ProjectOxford.Face.Contract;
using FaceBot.Helpers;
using FaceBot.Modelos;
namespace FaceBot.Servicios
{
public static class ServicioFace
{
public static async Task<Emocion> ObtenerEmocion(Stream foto)
{
Emocion emocion = null;
try
{
if (foto != null)
{
var clienteFace = new FaceServiceClient(Constantes.FaceApiKey, Constantes.FaceApiURL);
var atributosFace = new FaceAttributeType[] { FaceAttributeType.Emotion, FaceAttributeType.Age };
using (var stream = foto)
{
Face[] rostros = await clienteFace.DetectAsync(stream, false, false, atributosFace);
if (rostros.Any())
{
var analisisEmocion = rostros.FirstOrDefault().FaceAttributes.Emotion.ToRankedList().FirstOrDefault();
emocion = new Emocion()
{
Nombre = analisisEmocion.Key,
Score = analisisEmocion.Value
};
}
foto.Dispose();
}
}
}
catch (Exception ex)
{
}
return emocion;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.