Last active
June 30, 2016 03:37
-
-
Save sakapon/f781a949fe5062ea133d8f5240cfd695 to your computer and use it in GitHub Desktop.
CognitiveSample / FaceWpf / Detect faces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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