private async Task ResetStateAsync() { this.peopleListView.Children.Clear(); this.peopleInVideo.Clear(); await FaceListManager.ResetFaceLists(); this.demographics = new DemographicsData { AgeGenderDistribution = new AgeGenderDistribution { FemaleDistribution = new AgeDistribution(), MaleDistribution = new AgeDistribution() }, Visitors = new List <Visitor>() }; this.tagsInVideo.Clear(); this.tagFilterPanel.Children.Clear(); this.tagsListView.Children.Clear(); this.detectedObjectsInVideo.Clear(); this.detectedObjectFilterPanel.Children.Clear(); this.detectedObjectsListView.Children.Clear(); this.detectedObjectsInFrame.Clear(); this.pendingIdentificationAttemptCount.Clear(); this.processedFrames.Clear(); }
protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e) { this.isProcessingLoopInProgress = false; Window.Current.Activated -= CurrentWindowActivationStateChanged; this.cameraControl.CameraAspectRatioChanged -= CameraControl_CameraAspectRatioChanged; await FaceListManager.ResetFaceLists(); await this.cameraControl.StopStreamAsync(); base.OnNavigatingFrom(e); }
private async Task ResetDemographicsData() { this.initializingUI.Visibility = Visibility.Visible; this.initializingProgressRing.IsActive = true; this.demographics = new DemographicsData { StartTime = DateTime.Now, AgeGenderDistribution = new AgeGenderDistribution { FemaleDistribution = new AgeDistribution(), MaleDistribution = new AgeDistribution() }, Visitors = new List <Visitor>() }; this.visitors.Clear(); await FaceListManager.ResetFaceLists(); this.initializingUI.Visibility = Visibility.Collapsed; this.initializingProgressRing.IsActive = false; }
protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e) { this.isProcessingLoopInProgress = false; Window.Current.Activated -= CurrentWindowActivationStateChanged; this.cameraControl.CameraAspectRatioChanged -= CameraControl_CameraAspectRatioChanged; if (SettingsHelper.Instance.DriverMonitoringSleepingThreshold != this.SleepingApertureThreshold) { SettingsHelper.Instance.DriverMonitoringSleepingThreshold = this.SleepingApertureThreshold; } if (SettingsHelper.Instance.DriverMonitoringYawningThreshold != this.YawningApertureThreshold) { SettingsHelper.Instance.DriverMonitoringYawningThreshold = this.YawningApertureThreshold; } await FaceListManager.ResetFaceLists(); await this.cameraControl.StopStreamAsync(); base.OnNavigatingFrom(e); }
protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e) { await FaceListManager.ResetFaceLists(); base.OnNavigatingFrom(e); }
private async Task ProcessImagesAsync(StorageFolder rootFolder, bool forceProcessing = false) { this.progressRing.IsActive = true; this.landingMessage.Visibility = Visibility.Collapsed; this.filterTab.Visibility = Visibility.Visible; this.reprocessImagesButton.IsEnabled = true; this.FilteredResults.Clear(); this.AllResults.Clear(); this.TagFilters.Clear(); this.EmotionFilters.Clear(); this.FaceFilters.Clear(); List <ImageInsights> insightsList = new List <ImageInsights>(); if (!forceProcessing) { // see if we have pre-computed results and if so load it from the json file try { StorageFile insightsResultFile = (await rootFolder.TryGetItemAsync("ImageInsights.json")) as StorageFile; if (insightsResultFile != null) { using (StreamReader reader = new StreamReader(await insightsResultFile.OpenStreamForReadAsync())) { insightsList = JsonConvert.DeserializeObject <List <ImageInsights> >(await reader.ReadToEndAsync()); foreach (var insights in insightsList) { await AddImageInsightsToViewModel(rootFolder, insights); } } } } catch { // We will just compute everything again in case of errors } } if (!insightsList.Any()) { // start with fresh face lists await FaceListManager.ResetFaceLists(); // enumerate through the images and extract the insights QueryOptions fileQueryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { ".png", ".jpg", ".bmp", ".jpeg", ".gif" }); StorageFileQueryResult queryResult = rootFolder.CreateFileQueryWithOptions(fileQueryOptions); var queryFileList = this.limitProcessingToggleButton.IsChecked.Value ? await queryResult.GetFilesAsync(0, 50) : await queryResult.GetFilesAsync(); foreach (var item in queryFileList) { // Resize (if needed) in order to reduce network latency. Then store the result in a temporary file. StorageFile resizedFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("ImageCollectionInsights.jpg", CreationCollisionOption.GenerateUniqueName); var resizeTransform = await Util.ResizePhoto(await item.OpenStreamForReadAsync(), 720, resizedFile); // Send the file for processing ImageInsights insights = await ImageProcessor.ProcessImageAsync(resizedFile.OpenStreamForReadAsync, item.Name); // Delete resized file await resizedFile.DeleteAsync(); // Adjust all FaceInsights coordinates based on the transform function between the original and resized photos foreach (var faceInsight in insights.FaceInsights) { faceInsight.FaceRectangle.Left = (int)(faceInsight.FaceRectangle.Left * resizeTransform.Item1); faceInsight.FaceRectangle.Top = (int)(faceInsight.FaceRectangle.Top * resizeTransform.Item2); faceInsight.FaceRectangle.Width = (int)(faceInsight.FaceRectangle.Width * resizeTransform.Item1); faceInsight.FaceRectangle.Height = (int)(faceInsight.FaceRectangle.Height * resizeTransform.Item2); } insightsList.Add(insights); await AddImageInsightsToViewModel(rootFolder, insights); } // save to json StorageFile jsonFile = await rootFolder.CreateFileAsync("ImageInsights.json", CreationCollisionOption.ReplaceExisting); using (StreamWriter writer = new StreamWriter(await jsonFile.OpenStreamForWriteAsync())) { string jsonStr = JsonConvert.SerializeObject(insightsList, Formatting.Indented); await writer.WriteAsync(jsonStr); } } List <TagFilterViewModel> tagsGroupedByCountAndSorted = new List <TagFilterViewModel>(); foreach (var group in this.TagFilters.GroupBy(t => t.Count).OrderByDescending(g => g.Key)) { tagsGroupedByCountAndSorted.AddRange(group.OrderBy(t => t.Tag)); } this.TagFilters.Clear(); this.TagFilters.AddRange(tagsGroupedByCountAndSorted); var sortedEmotions = this.EmotionFilters.OrderByDescending(e => e.Count).ToArray(); this.EmotionFilters.Clear(); this.EmotionFilters.AddRange(sortedEmotions); var sortedFaces = this.FaceFilters.OrderByDescending(f => f.Count).ToArray(); this.FaceFilters.Clear(); this.FaceFilters.AddRange(sortedFaces); this.progressRing.IsActive = false; }
private async void DeleteSimilarFacesButton_Click(object sender, RoutedEventArgs e) { await FaceListManager.ResetFaceLists(); }
private async Task ProcessImagesAsync(StorageFolder rootFolder) { this.progressRing.IsActive = true; this.AllResults.Clear(); this.FilteredResults.Clear(); this.TagFilters.Clear(); this.EmotionFilters.Clear(); this.FaceFilters.Clear(); List <ImageInsights> insightsList = new List <ImageInsights>(); // see if we have pre-computed results and if so load it from the json file try { StorageFile insightsResultFile = (await rootFolder.TryGetItemAsync("ImageInsights.json")) as StorageFile; if (insightsResultFile != null) { using (StreamReader reader = new StreamReader(await insightsResultFile.OpenStreamForReadAsync())) { insightsList = JsonConvert.DeserializeObject <List <ImageInsights> >(await reader.ReadToEndAsync()); foreach (var insights in insightsList) { await AddImageInsightsToViewModel(rootFolder, insights); } } } } catch { // We will just compute everything again in case of errors } if (!insightsList.Any()) { // start with fresh face lists await FaceListManager.ResetFaceLists(); // enumerate through the first 50 images and extract the insights QueryOptions fileQueryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { ".png", ".jpg", ".bmp", ".jpeg", ".gif" }); StorageFileQueryResult queryResult = rootFolder.CreateFileQueryWithOptions(fileQueryOptions); foreach (var item in (await queryResult.GetFilesAsync(0, 50))) { try { // Resize (if needed) in order to reduce network latency and errors due to large files. Then store the result in a temporary file. StorageFile resizedFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("ImageCollectionInsights.jpg", CreationCollisionOption.GenerateUniqueName); var resizeTransform = await Util.ResizePhoto(await item.OpenStreamForReadAsync(), 720, resizedFile); // Send the file for processing ImageInsights insights = await ImageProcessor.ProcessImageAsync(resizedFile.OpenStreamForReadAsync, item.Name); // Delete resized file await resizedFile.DeleteAsync(); // Adjust all FaceInsights coordinates based on the transform function between the original and resized photos foreach (var faceInsight in insights.FaceInsights) { faceInsight.FaceRectangle.Left = (int)(faceInsight.FaceRectangle.Left * resizeTransform.Item1); faceInsight.FaceRectangle.Top = (int)(faceInsight.FaceRectangle.Top * resizeTransform.Item2); faceInsight.FaceRectangle.Width = (int)(faceInsight.FaceRectangle.Width * resizeTransform.Item1); faceInsight.FaceRectangle.Height = (int)(faceInsight.FaceRectangle.Height * resizeTransform.Item2); } insightsList.Add(insights); await AddImageInsightsToViewModel(rootFolder, insights); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Error processing image."); } } // save to json StorageFile jsonFile = await rootFolder.CreateFileAsync("ImageInsights.json", CreationCollisionOption.ReplaceExisting); using (StreamWriter writer = new StreamWriter(await jsonFile.OpenStreamForWriteAsync())) { string jsonStr = JsonConvert.SerializeObject(insightsList, Formatting.Indented); await writer.WriteAsync(jsonStr); } } var sortedTags = this.TagFilters.OrderBy(t => t.Tag).ToArray(); this.TagFilters.Clear(); this.TagFilters.AddRange(sortedTags); var sortedEmotions = this.EmotionFilters.OrderBy(t => t.Emotion).ToArray(); this.EmotionFilters.Clear(); this.EmotionFilters.AddRange(sortedEmotions); this.progressRing.IsActive = false; }
private async Task ProcessImagesAsync(StorageFolder rootFolder, bool forceProcessing = false) { this.progressRing.IsActive = true; this.landingMessage.Visibility = Visibility.Collapsed; this.filterTab.Visibility = Visibility.Visible; this.reprocessImagesButton.IsEnabled = true; this.FilteredResults.Clear(); this.AllResults.Clear(); this.TagFilters.Clear(); this.EmotionFilters.Clear(); this.FaceFilters.Clear(); List <ImageInsights> insightsList = new List <ImageInsights>(); if (!forceProcessing) { try { StorageFile insightsResultFile = (await rootFolder.TryGetItemAsync("ImageInsights.json")) as StorageFile; if (insightsResultFile != null) { using (StreamReader reader = new StreamReader(await insightsResultFile.OpenStreamForReadAsync())) { insightsList = JsonConvert.DeserializeObject <List <ImageInsights> >(await reader.ReadToEndAsync()); foreach (var insights in insightsList) { await AddImageInsightsToViewModel(rootFolder, insights); } } } } catch { } } if (!insightsList.Any()) { await FaceListManager.ResetFaceLists(); QueryOptions fileQueryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { ".png", ".jpg", ".bmp", ".jpeg", ".gif" }); StorageFileQueryResult queryResult = rootFolder.CreateFileQueryWithOptions(fileQueryOptions); var queryFileList = this.limitProcessingToggleButton.IsChecked.Value ? await queryResult.GetFilesAsync(0, 50) : await queryResult.GetFilesAsync(); foreach (var item in queryFileList) { StorageFile resizedFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("ImageCollectionInsights.jpg", CreationCollisionOption.GenerateUniqueName); var resizeTransform = await Util.ResizePhoto(await item.OpenStreamForReadAsync(), 720, resizedFile); ImageInsights insights = await ImageProcessor.ProcessImageAsync(resizedFile.OpenStreamForReadAsync, item.Name); await resizedFile.DeleteAsync(); foreach (var faceInsight in insights.FaceInsights) { faceInsight.FaceRectangle.Left = (int)(faceInsight.FaceRectangle.Left * resizeTransform.Item1); faceInsight.FaceRectangle.Top = (int)(faceInsight.FaceRectangle.Top * resizeTransform.Item2); faceInsight.FaceRectangle.Width = (int)(faceInsight.FaceRectangle.Width * resizeTransform.Item1); faceInsight.FaceRectangle.Height = (int)(faceInsight.FaceRectangle.Height * resizeTransform.Item2); } insightsList.Add(insights); await AddImageInsightsToViewModel(rootFolder, insights); } StorageFile jsonFile = await rootFolder.CreateFileAsync("ImageInsights.json", CreationCollisionOption.ReplaceExisting); using (StreamWriter writer = new StreamWriter(await jsonFile.OpenStreamForWriteAsync())) { string jsonStr = JsonConvert.SerializeObject(insightsList, Formatting.Indented); await writer.WriteAsync(jsonStr); } } List <TagFilterViewModel> tagsGroupedByCountAndSorted = new List <TagFilterViewModel>(); foreach (var group in this.TagFilters.GroupBy(t => t.Count).OrderByDescending(g => g.Key)) { tagsGroupedByCountAndSorted.AddRange(group.OrderBy(t => t.Tag)); } this.TagFilters.Clear(); this.TagFilters.AddRange(tagsGroupedByCountAndSorted); var sortedEmotions = this.EmotionFilters.OrderByDescending(e => e.Count).ToArray(); this.EmotionFilters.Clear(); this.EmotionFilters.AddRange(sortedEmotions); var sortedFaces = this.FaceFilters.OrderByDescending(f => f.Count).ToArray(); this.FaceFilters.Clear(); this.FaceFilters.AddRange(sortedFaces); this.progressRing.IsActive = false; }