private async Task UpdateResultsAsync()

in Kiosk/Views/VisionApiExplorer.xaml.cs [137:244]


        private async Task UpdateResultsAsync(ImageAnalyzer img)
        {
            //convert results to OverlayInfo
            var faces = img.AnalysisResult.Faces.Select(i => new FaceOverlayInfo(i, GetCelebrity(i, img.AnalysisResult)) { IsMuted = true }).ToArray();
            var objects = img.AnalysisResult.Objects.Select(i => new ObjectOverlayInfo(i) { IsMuted = true }).ToArray();
            var brands = img.AnalysisResult.Brands.Select(i => new ObjectOverlayInfo(i) { IsMuted = true }).ToArray();

            //extract crops from the image
            var stream = img.ImageUrl == null ? await img.GetImageStreamCallback() : new MemoryStream(await new HttpClient().GetByteArrayAsync(img.ImageUrl));

            using (stream)
            {
                foreach (var face in faces)
                {
                    face.EntityExt.Image = await Util.GetCroppedBitmapAsync(stream.AsRandomAccessStream(), face.Rect);
                }
                foreach (var obj in objects)
                {
                    obj.EntityExt.Image = await Util.GetCroppedBitmapAsync(stream.AsRandomAccessStream(), obj.Rect);
                }
                foreach (var brand in brands)
                {
                    brand.EntityExt.Image = await Util.GetCroppedBitmapAsync(stream.AsRandomAccessStream(), brand.Rect);
                }
            }

            //apply results
            Celebrities = faces.Where(i => i.IsCelebrity).ToArray();
            Faces = faces.Where(i => !i.IsCelebrity).ToArray();
            Objects = objects;
            Brands = brands;
            OverlayPresenter.FaceInfo = Faces;
            OverlayPresenter.ObjectInfo = objects.Concat(brands).ToArray();


            if (img.AnalysisResult.Tags == null || !img.AnalysisResult.Tags.Any())
            {
                this.tagsGridView.ItemsSource = new[] { new { Name = "No tags" } };
            }
            else
            {
                var tags = img.AnalysisResult.Tags.Select(t => new { Confidence = string.Format("({0}%)", Math.Round(t.Confidence * 100)), Name = t.Name });
                if (!ShowAgeAndGender)
                {
                    tags = tags.Where(t => !Util.ContainsGenderRelatedKeyword(t.Name));
                }

                this.tagsGridView.ItemsSource = tags;
            }

            if (img.AnalysisResult.Description == null || !img.AnalysisResult.Description.Captions.Any(d => d.Confidence >= 0.2))
            {
                this.descriptionGridView.ItemsSource = new[] { new { Description = "Not sure what that is" } };
            }
            else
            {
                var descriptions = img.AnalysisResult.Description.Captions.Select(d => new { Confidence = string.Format("({0}%)", Math.Round(d.Confidence * 100)), Description = d.Text });
                if (!ShowAgeAndGender)
                {
                    descriptions = descriptions.Where(t => !Util.ContainsGenderRelatedKeyword(t.Description));
                }

                if (descriptions.Any())
                {
                    this.descriptionGridView.ItemsSource = descriptions;
                }
                else
                {
                    this.descriptionGridView.ItemsSource = new[] { new { Description = "Please enable Age/Gender prediction in the Settings Page to see the results" } };
                }
            }

            var landmarkNames = this.GetLandmarkNames(img);
            if (landmarkNames == null || !landmarkNames.Any())
            {
                this.landmarksTextBlock.Text = NoneDesc;
            }
            else
            {
                this.landmarksTextBlock.Text = string.Join(", ", landmarkNames.OrderBy(name => name).Distinct());
            }

            if (img.AnalysisResult.Color == null)
            {
                this.colorInfoListView.ItemsSource = new[] { new { Description = "Not available" } };
            }
            else
            {
                this.colorInfoListView.ItemsSource = new[]
                {
                    new { Description = "Background", Colors = new string[] { img.AnalysisResult.Color.DominantColorBackground } },
                    new { Description = "Foreground", Colors = new string[] { img.AnalysisResult.Color.DominantColorForeground } },
                    new { Description = "Dominant", Colors = img.AnalysisResult.Color.DominantColors?.ToArray() },
                    new { Description = "Accent", Colors = new string[] { "#" + img.AnalysisResult.Color.AccentColor } }
                };
            }

            NoItemsDescription = NoneDesc;

            //update summaries
            FacesTab.Summary = SummaryBuilder((Faces?.Count(), "face", "faces"), (Celebrities?.Count(), "celebrity", "celebrities"));
            ObjectsTab.Summary = SummaryBuilder((Objects?.Count(), "object", "objects"), (Brands?.Count(), "brand", "brands"));

            //update muted items
            SetMute(SelectedTab);

            Processing.IsActive = false;
        }