// MARK: Video Deletion Functions private void AnalyzeDeleteClicked(object sender, RoutedEventArgs e) //delete the selected video { BarInteraction(); AnalysisVideo selectedVideo = (AnalysisVideo)AnalyzedListBox.SelectedItem; if (MessageBox.Show("Are you sure you want to delete " + selectedVideo.Name + "?", "Delete Video", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { EnableInteraction(); } else { int selectedIndex = AnalyzedListBox.SelectedIndex; CurrentProject.AnalysisVideos.RemoveAt(selectedIndex); AnalyzedListBox.ItemsSource = CurrentProject.AnalysisVideos; AnalyzedListBox.UpdateLayout(); string dir = CurrentProject.ConfigPath.Substring(0, CurrentProject.ConfigPath.LastIndexOf("\\")) + "\\analyzed-videos\\" + selectedVideo.Name; foreach (var file in Directory.GetFiles(dir)) { if (!file.Equals(selectedVideo.ThumbnailPath)) { File.Delete(file); } } //Directory.Delete(dir); SyncUI(); EnableInteraction(); } }
private void AnalyzeGaitButton_Click(object sender, RoutedEventArgs e) { AnalysisVideo vid = (AnalysisVideo)GaitListBox.SelectedItem; //get the selected video if (vid != null) { string gaitVideoPath = vid.Path; //extract necessary info from the video string gaitVideoName = gaitVideoPath.Substring(gaitVideoPath.LastIndexOf("\\") + 1, gaitVideoPath.LastIndexOf(".") - gaitVideoPath.LastIndexOf("\\")); string gaitTempPath = gaitVideoPath.Substring(0, gaitVideoPath.LastIndexOf("\\")) + "\\temp-" + gaitVideoName; var files = Directory.EnumerateFiles(gaitTempPath); var file = ""; //might crash foreach (var currentImg in files) { if (currentImg.Contains(".png")) { file = currentImg; break; } } BarInteraction(); // Check if Gait data is saved from before string stateFolder = gaitVideoPath.Substring(0, gaitVideoPath.LastIndexOf("\\")) + "\\gaitsavedstate"; if (Directory.Exists(stateFolder) && File.Exists(stateFolder + "\\inputParams.txt")) { GaitWindow gaitWindow = new GaitWindow(gaitVideoPath, gaitVideoName, gaitTempPath); if (gaitWindow.ShowDialog() == true) { SyncUI(); } EnableInteraction(); } else //input params not saved, ask the user for'em { MeasureWindow window = new MeasureWindow(file, stateFolder); //spawn a window through which the user will give us the treadmill speed and a real world reference (for distance measurements) if (window.ShowDialog() == true) { double realWorldMultiplier = window.getSinglePixelSize(); float treadmillSpeed = float.Parse(window.TreadmillSpeedTextBox.Text); bool isFreeRun = false; if ((bool)window.AnalysisTypeRadioFreeWalking.IsChecked) { isFreeRun = true; } GaitWindow gaitWindow = new GaitWindow(realWorldMultiplier, treadmillSpeed, gaitVideoPath, gaitVideoName, gaitTempPath, isFreeRun); if (gaitWindow.ShowDialog() == true) { SyncUI(); } EnableInteraction(); } else { EnableInteraction(); } } } }
private void DragDropped(object sender, DragEventArgs e) //dropped a dragged item above the Gait "combined export" Listbox { DragTarget = (ListBox)sender; AnalysisVideo draggedData = (AnalysisVideo)DragSource.SelectedItem; if (!GaitCombinedVideos.Contains(draggedData) && draggedData.IsGaitAnalyzed) { GaitCombinedVideos.Add(draggedData); GaitCombineListBox.ItemsSource = null; GaitCombineListBox.ItemsSource = GaitCombinedVideos; DragNDropLabel.Visibility = Visibility.Collapsed; if (GaitCombinedVideos.Count > 1) { CombineResultsButton.IsEnabled = true; } } }
private void GaitListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) //change button description depending on whether gait has been analyzed on a particular video { AnalysisVideo selectedVid = (AnalysisVideo)GaitListBox.SelectedItem; if (selectedVid != null) { AnalyzeGaitButton.IsEnabled = true; if (selectedVid.IsGaitAnalyzed) { AnalyzeGaitButton.Content = "View/Edit"; } else { AnalyzeGaitButton.Content = "Analyze Gait"; } } else { AnalyzeGaitButton.IsEnabled = false; } }
private void EditDotSizeInConfig(int pos) //update dot size for analyzed labeled videos { AnalysisVideo video = CurrentProject.AnalysisVideos[pos]; StreamReader sr = new StreamReader(video.Path.Substring(0, video.Path.LastIndexOf("\\")) + "\\settings.txt"); String[] rows = Regex.Split(sr.ReadToEnd(), "\r\n"); string dotsize = "5"; foreach (string row in rows) { if (row.Contains("dotsize:")) { dotsize = row.Substring(row.IndexOf(":") + 2); dotsize = dotsize.Replace(" ", String.Empty); break; } } sr.Close(); StreamReader sr1 = new StreamReader(CurrentProject.ConfigPath); String[] configRows = Regex.Split(sr1.ReadToEnd(), "\r\n"); for (int i = 0; i < configRows.Count(); i++) { if (configRows[i].Contains("dotsize:")) { configRows[i] = "dotsize: " + dotsize; break; } } sr1.Close(); StreamWriter sw = new StreamWriter(CurrentProject.ConfigPath); for (int i = 0; i < configRows.Count(); i++) { sw.WriteLine(configRows[i]); } sw.Close(); }
// MARK: Loading Project - Analysis Videos private void LoadAnalysisVideos() //load analysis video into the CurrentProject variable from the "analyzed-videos" folder { string analyzedVideosPath = CurrentProject.ConfigPath.Substring(0, CurrentProject.ConfigPath.LastIndexOf("\\")); analyzedVideosPath = analyzedVideosPath + @"\analyzed-videos"; CurrentProject.AnalysisVideos = new List <AnalysisVideo>(); if (Directory.Exists(analyzedVideosPath)) { var dirs = Directory.EnumerateDirectories(analyzedVideosPath); foreach (var dir in dirs) { AnalysisVideo newVideo = new AnalysisVideo(); newVideo.Name = dir.Substring(dir.LastIndexOf("\\") + 1); newVideo.ThumbnailPath = "thumbnail.png"; var files = Directory.GetFiles(analyzedVideosPath + "\\" + newVideo.Name); newVideo.IsAnalyzed = false; newVideo.AnalyzedImageName = "Images/cross.png"; foreach (var file in files) { if ((file.Contains(".mp4") || file.Contains(".avi")) && (!file.Contains("labeled"))) { newVideo.Path = file; } if (file.Contains(".h5")) { newVideo.IsAnalyzed = true; newVideo.AnalyzedImageName = "Images/check.png"; } //check if teh video is analyzed if (file.Contains(".png")) { newVideo.ThumbnailPath = file; } } if (newVideo.Path != null) { CurrentProject.AnalysisVideos.Add(newVideo); } } } }