public async void InvokeFacebookCommand() { IsBusy = true; if (!CrossConnectivity.Current.IsConnected) { await App.Current.MainPage.DisplayAlert("Bache App", "Sin Internet :(", "Ok"); } else { if (await LoginFB()) { var result = await App.Current.MainPage.DisplayAlert("Bache App", "Alto Humano Demuestra que no eres un robot", "Ok", "Cancel"); if (result) { try { var config = new StoreCameraMediaOptions { DefaultCamera = CameraDevice.Front, PhotoSize = PhotoSize.Medium }; var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(config); using (var steam = photo.GetStream()) { var emotions = await ServiceEmotions.GetEmotions(photo.GetStream()); if (emotions != null) { var message = "Bienvenido Humano" + Environment.NewLine; foreach (var item in emotions) { message += item.Key + " : " + item.Value + Environment.NewLine; } await App.Current.MainPage.DisplayAlert("Bache App", message, "Ok"); App.GoToMainPage(); Settings.IsLoggedIn = true; } } } catch { await App.Current.MainPage.DisplayAlert("Bache App", "Atras Robot", "Ok", "Cancel"); } } } } IsBusy = false; }
private async void BtnAnalizaFoto_Click(object sender, System.EventArgs e) { if (streamCopy != null) { btnAnalizaFoto.Visibility = Android.Views.ViewStates.Invisible; Toast.MakeText(this, "Analizndo imagen usando cognitive services", ToastLength.Short).Show(); Dictionary <string, float> emotions = null; try { streamCopy.Seek(0, SeekOrigin.Begin); emotions = await ServiceEmotions.GetEmotions(streamCopy); } catch (Exception) { Toast.MakeText(this, "Ha ocurrido un error en la conexion a los servicios.", ToastLength.Short).Show(); return; } StringBuilder builder = new StringBuilder(); if (emotions != null) { txtResultado.Text = "---Analisis de emociones---"; builder.AppendLine(); foreach (var emotion in emotions) { string toAdd = emotion.Key + " : " + emotion.Value + " "; builder.Append(toAdd); } txtResultado.Text += builder.ToString(); btnRegistrarResultados.Visibility = Android.Views.ViewStates.Visible; } else { txtResultado.Text = "---No se detecto cara---"; } resultadoEmociones += builder.ToString(); } else { txtResultado.Text = "--no se ha seleccionado una imagen---"; } }
private async void BtnAnalizaFoto_Click(object sender, EventArgs e) { if (streamCopy != null) { btnAnalizaFoto.Visibility = ViewStates.Invisible; Toast.MakeText(this, "Analizando imagen utilizando Cognitive Services", ToastLength.Short).Show(); Dictionary <string, float> emotions = null; try { streamCopy.Seek(0, SeekOrigin.Begin); emotions = await ServiceEmotions.GetEmotions(streamCopy); } catch (Exception ex) { Toast.MakeText(this, "Se ha presentado un error al conectar con los servicios", ToastLength.Short).Show(); return; } StringBuilder sb = new StringBuilder(); if (emotions != null) { txtResultado.Text = "---Análisis de Emociones---"; sb.AppendLine(); foreach (var item in emotions) { string toAdd = item.Key + " : " + item.Value + " "; sb.Append(toAdd); } txtResultado.Text += sb.ToString(); btnRegistraResultados.Visibility = ViewStates.Visible; } else { txtResultado.Text = "---No se detectó una cara---"; } ResultadoEmociones += sb.ToString(); } else { txtResultado.Text = "---No has seleccionado una imagen---"; } }
async void btnAnalysisEmotions_Clicked(object sender, EventArgs e) { if (streamCopy != null) { streamCopy.Seek(0, SeekOrigin.Begin); var emotions = await ServiceEmotions.GetEmotions(streamCopy); if (emotions != null) { lblResult.Text = "---Análisis de Emociones---"; DrawResults(emotions); } else { lblResult.Text = "---No se detectó una cara---"; } } else { lblResult.Text = "---No has seleccionado una imagen---"; } }
async void btnAnalysisEmotions_Clicked(object sender, EventArgs e) { if (streamCopy != null) { streamCopy.Seek(0, SeekOrigin.Begin); var emotions = await ServiceEmotions.GetEmotions(streamCopy); if (emotions != null) { lblResult.Text = "Este es el resultado de como te sientes:"; DrawResults(emotions); } else { lblResult.Text = "Ups! no detectamos ningun rostro :("; } } else { lblResult.Text = "No has seleccionado ninguna imagen"; } }