Skip to content

Instantly share code, notes, and snippets.

@sakapon
Last active June 30, 2016 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakapon/f781a949fe5062ea133d8f5240cfd695 to your computer and use it in GitHub Desktop.
Save sakapon/f781a949fe5062ea133d8f5240cfd695 to your computer and use it in GitHub Desktop.
CognitiveSample / FaceWpf / Detect faces
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using Microsoft.ProjectOxford.Face;
namespace FaceWpf
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
const string SubscriptionKey = "0123456789abcdef0123456789abcdef";
const string ImagePath = @"Images\temp.jpg";
FaceServiceClient client = new FaceServiceClient(SubscriptionKey);
async void DetectAsync()
{
try
{
using (var stream = File.OpenRead(ImagePath))
{
var faces = await client.DetectAsync(stream, returnFaceAttributes: (FaceAttributeType[])Enum.GetValues(typeof(FaceAttributeType)));
// 各情報を取り出します。
var age = faces[0].FaceAttributes.Age;
var rectangle = faces[0].FaceRectangle;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment