static void Main(string[] args) { string subscriptionKey = "4c138b4d82b947beb2e2926c92d1e514"; var client = new Microsoft.ProjectOxford.Face.FaceServiceClient(subscriptionKey); GetFaces(client); Console.ReadLine(); }
private async void DetectAsync() { Shell.SetBusyVisibility( Visibility.Visible, "Taking photo.." ); this.operationMode = OperationMode.Detect; this.viewModel.PhotoFile = await this.camera.CapturePhotoToFileAsync(); await this.camera.CaptureManager.StopPreviewAsync(); if( this.led != null ) { this.led.TurnOff(); } Shell.SetBusyVisibility( Visibility.Visible, "Detecting your face.." ); Face.FaceServiceClient faceClient = new Face.FaceServiceClient( FACE_API_KEY ); Stream stream = await this.viewModel.PhotoFile.OpenStreamForReadAsync(); Face.Contract.Face[] faces = await faceClient.DetectAsync( stream, analyzesAge: true, analyzesGender: true ); VoiceGender voiceGender = VoiceGender.Male; if( faces.Length == 1 ) { Face.Contract.FaceAttribute face = faces[ 0 ].Attributes; string greet; if( face.Gender == "male" ) { greet = "Hello Handsome!"; voiceGender = VoiceGender.Female; } else { greet = "Hey, Sexy!"; voiceGender = VoiceGender.Male; } this.viewModel.Greet = $"{greet} You look {face.Age} today."; await this.SpeakAsync( this.viewModel.Greet, voiceGender, true ); } else { this.viewModel.Greet = "I cannot see your face :("; } Shell.SetBusyVisibility( Visibility.Visible, "Detecting your emotions.." ); Emotion.EmotionServiceClient emotionClient = new Emotion.EmotionServiceClient( EMOTION_API_KEY ); stream = await this.viewModel.PhotoFile.OpenStreamForReadAsync(); Emotion.Contract.Emotion[] emotions = await emotionClient.RecognizeAsync( stream ); if( emotions.Length == 1 ) { Emotion.Contract.Scores scores = emotions[ 0 ].Scores; this.viewModel.Scores = scores; bool like = scores.Happiness > scores.Anger + scores.Sadness + scores.Disgust; this.viewModel.EvaluationResult = like ? "So you liked it! I'm so happy to hear that! :)" : "Oh, really? I'm terribly sorry! :("; await this.SpeakAsync( this.viewModel.EvaluationResult, voiceGender, false ); } else { this.viewModel.EvaluationResult = "I cannot see your emotions :("; } this.operationMode = OperationMode.Done; Shell.SetBusyVisibility( Visibility.Collapsed ); }