public void UpdateEvent(CognitiveEvent mainEvent) { if (mainEvent.ImageAnalysis.Description.Captions.Count > 0) { textDescription.Text = mainEvent.ImageAnalysis.Description.Captions.FirstOrDefault().Text; } }
public void UpdateEvent(CognitiveEvent mainEvent) { if (mainEvent.ClearData) { textTranslationOriginalRT.Text = ""; textTranslationRT.Text = ""; textTranslationOriginal.Text = ""; textTranslation.Text = ""; } if (!string.IsNullOrEmpty(mainEvent.PrimarySpeechMessage)) { textTranslationOriginalRT.Text = mainEvent.PrimarySpeechMessage; textTranslationRT.Text = mainEvent.SecondarySpeechMessage; } if (!string.IsNullOrEmpty(mainEvent.PrimarySpeechMessageFinal)) { textTranslationOriginal.Text = mainEvent.PrimarySpeechMessageFinal; textTranslation.Text = mainEvent.SecondarySpeechMessageFinal; } }
public void UpdateEvent(CognitiveEvent mainEvent) { if (lastRefresh < DateTime.Now.AddMinutes(-1)) { lastRefresh = DateTime.Now; people.Clear(); borderTop.Visibility = Visibility.Collapsed; } try { if (mainEvent.ImageAnalysis != null) { textTags.Text = "Pretrained: "; textTags.Text += string.Join(",", mainEvent.ImageAnalysis.Tags.Select(x => x.Name)); if (mainEvent.ImageAnalysis.Brands != null && mainEvent.ImageAnalysis.Brands.Count > 0) { textTags.Text += "\n\n" + mainEvent.ImageAnalysis.Brands.First().Name + " Logo"; } } } catch (Exception) { textTags.Text += "\n Image analysis failed"; } if (mainEvent.IdentifiedPerson != null) { borderTop.Visibility = Visibility.Visible; if (people.Count(x => x.Name == mainEvent.IdentifiedPerson.Name) == 0) { people.Add(mainEvent.IdentifiedPerson); } textPeople.Text = "Welcome back " + string.Join(" and ", people.Select(x => x.Name).ToArray()); } }
public void UpdateEvent(CognitiveEvent mainEvent) { if (mainEvent.ImageAnalysisCV == null || mainEvent.ImageAnalysisCV.Predictions == null) { if (mainEvent.ImageAnalysis.Description.Captions.Count > 0) { textDescription.Text = mainEvent.ImageAnalysis.Description.Captions.FirstOrDefault().Text; } } if (mainEvent.ImageAnalysisCV != null && mainEvent.ImageAnalysisCV.Predictions != null) { var preds = mainEvent.ImageAnalysisCV.Predictions.Where(x => x.Probability >= settings.CustomVisionThreshold / 100d).ToList(); if (preds.Count() > 0) { textDescription.Text = "Custom Vision: " + string.Join(",", preds.Select(x => x.TagName).Distinct()); for (int i = 0; i < preds.Count(); i++) { var pred = preds[i]; //int convertedTop = (int)((pred.BoundingBox.Top * (int)captureControl.ActualHeight) / mainEvent.ImageHeight) - ((int)captureControl.Margin.Top); //int convertedLeft = (int)(((pred.BoundingBox.Left) * (int)captureControl.ActualWidth) / mainEvent.ImageWidth) - ((int)captureControl.Margin.Left); int convertedTop = (int)((pred.BoundingBox.Top * captureControl.ActualHeight)); int convertedLeft = (int)((pred.BoundingBox.Left * captureControl.ActualWidth)); int width = (int)(pred.BoundingBox.Width * captureControl.ActualWidth); int height = (int)(pred.BoundingBox.Height * captureControl.ActualHeight); ObjectBox uc = null; Brush brush = null; switch (i) { case 0: uc = box1; brush = brush1; box1.Visibility = Visibility.Visible; break; case 1: uc = box2; brush = brush2; box2.Visibility = Visibility.Visible; break; case 2: uc = box3; brush = brush3; box3.Visibility = Visibility.Visible; break; case 3: uc = box4; brush = brush4; box4.Visibility = Visibility.Visible; break; } if (uc != null) { UpdateBox(uc, convertedLeft, convertedTop, width, height, pred.TagName + " " + pred.Probability.ToString("P"), brush); } } } else if (mainEvent.ImageAnalysis.Description.Captions.Count > 0) { textDescription.Text = mainEvent.ImageAnalysis.Description.Captions.FirstOrDefault().Text; } else { textDescription.Text = ""; } for (int i = preds.Count(); i < 4; i++) { switch (i) { case 0: box1.Visibility = Visibility.Collapsed; break; case 1: box2.Visibility = Visibility.Collapsed; break; case 2: box3.Visibility = Visibility.Collapsed; break; case 3: box4.Visibility = Visibility.Collapsed; break; } } } }
public void UpdateEvent(CognitiveEvent mainEvent) { textTranslationOriginal.Text = mainEvent.PrimarySpeechMessage; textTranslation.Text = mainEvent.SecondarySpeechMessage; }
public void UpdateEvent(CognitiveEvent mainEvent) { var faces = mainEvent.Faces; try { var task = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { try { if (faces.Count() == 0) { textFaceTotal.Text = $"I don't see anyone! Smile!"; } else { textFaceTotal.Text = $"{faces.Count.ToString()} faces with {faces.Average(x => x.FaceAttributes.Emotion.Happiness).ToString("0.0%")} happiness"; } } catch (Exception) { textFaceTotal.Text = ""; } textFaces1.Text = ""; textFaces2.Text = ""; textFaces3.Text = ""; if (faces.Count() >= 3) { ageControl1.Visibility = Visibility.Visible; ageControl2.Visibility = Visibility.Visible; ageControl3.Visibility = Visibility.Visible; } else if (faces.Count() >= 2) { ageControl1.Visibility = Visibility.Visible; ageControl2.Visibility = Visibility.Visible; ageControl3.Visibility = Visibility.Collapsed; } else if (faces.Count() >= 1) { ageControl1.Visibility = Visibility.Visible; ageControl2.Visibility = Visibility.Collapsed; ageControl3.Visibility = Visibility.Collapsed; } else if (faces.Count() >= 0) { ageControl1.Visibility = Visibility.Collapsed; ageControl2.Visibility = Visibility.Collapsed; ageControl3.Visibility = Visibility.Collapsed; } var facesSorted = faces.Take(3).OrderBy(x => x.FaceRectangle.Left).ToList(); for (int i = 0; i < facesSorted.Count(); i++) { var face = facesSorted[i]; int convertedTop = ((face.FaceRectangle.Top * (int)captureControl.ActualHeight) / mainEvent.ImageHeight) - ((int)captureControl.Margin.Top) - ((int)ageControl1.ActualHeight); int convertedLeft = (((face.FaceRectangle.Left + (face.FaceRectangle.Width / 4)) * (int)captureControl.ActualWidth) / mainEvent.ImageWidth); double maxEmotion = face.FaceAttributes.Emotion.Anger; string choosenEmotion = "Anger"; if (face.FaceAttributes.Emotion.Contempt > maxEmotion) { maxEmotion = face.FaceAttributes.Emotion.Contempt; choosenEmotion = "Contempt"; } if (face.FaceAttributes.Emotion.Disgust > maxEmotion) { maxEmotion = face.FaceAttributes.Emotion.Disgust; choosenEmotion = "Disgust"; } if (face.FaceAttributes.Emotion.Fear > maxEmotion) { maxEmotion = face.FaceAttributes.Emotion.Fear; choosenEmotion = "Fear"; } if (face.FaceAttributes.Emotion.Happiness > maxEmotion) { maxEmotion = face.FaceAttributes.Emotion.Happiness; choosenEmotion = "Happiness"; } if (face.FaceAttributes.Emotion.Neutral > maxEmotion) { maxEmotion = face.FaceAttributes.Emotion.Neutral; choosenEmotion = "Neutral"; } if (face.FaceAttributes.Emotion.Sadness > maxEmotion) { maxEmotion = face.FaceAttributes.Emotion.Sadness; choosenEmotion = "Sadness"; } if (face.FaceAttributes.Emotion.Surprise > maxEmotion) { maxEmotion = face.FaceAttributes.Emotion.Surprise; choosenEmotion = "Surprise"; } string hair = ""; if (face.FaceAttributes.Hair.Bald > .6) { hair = "bald"; } else { if (face.FaceAttributes.Hair.HairColor.Count > 0) { hair = face.FaceAttributes.Hair.HairColor.First().Color.ToString(); } } string userInfo = $"Emotion: {choosenEmotion} \nGlasses: {face.FaceAttributes.Glasses.ToString()} \nSmile: {face.FaceAttributes.Smile.ToString()} \nHair: {hair} "; AgeControl ageControl = null; switch (i) { case 0: ageControl = ageControl1; textFaces1.Text = userInfo; break; case 1: ageControl = ageControl2; textFaces2.Text = userInfo; break; case 2: ageControl = ageControl3; textFaces3.Text = userInfo; break; } if (ageControl == null) { break; } ageControl.Margin = new Thickness(convertedLeft, convertedTop, 0, 0); ageControl.Visibility = Visibility; ageControl.SetUserInfo(i + 1, face.FaceAttributes.Gender.ToString(), face.FaceAttributes.Age, choosenEmotion); } }); } catch (Exception ex) { Debug.WriteLine(ex.Message); //Eat excepiton } }