/// <summary> /// Raises the corresponding event. /// </summary> private void onExportFinished(object parameter) { object[] parameters = parameter as object[]; OpenNIRecordingController sender = parameters[0] as OpenNIRecordingController; DirectoryInfo exportDir = parameters[1] as DirectoryInfo; List <int> frames = parameters[2] as List <int>; List <int> userIDs = parameters[3] as List <int>; ImageDictionary exported_file_information2D = parameters[4] as ImageDictionary; ImageDictionary exported_file_information3D = parameters[5] as ImageDictionary; bool ExportRelativePathNames = (bool)parameters[6]; String export_filename_suffix = parameters[7] as String; if (exportThread != null && exportThread.IsAlive) { exportThread.Join(); } if (ExportFinished != null) { ExportFinished(sender, exportDir, frames, userIDs, exported_file_information2D, exported_file_information3D, ExportRelativePathNames, export_filename_suffix); } }
private void checkedListBoxBodyParts_ItemCheck(object sender, ItemCheckEventArgs e) { SkeletonJoint changedJoint = JointDictionary.GetTranslation((String)checkedListBoxBodyParts.Items[e.Index]).joint_type; chartErrors.Series[(String)checkedListBoxBodyParts.Items[e.Index]].Enabled = (e.NewValue == CheckState.Checked); foreach (Annotation annotation in annotations[changedJoint]) { annotation.Visible = e.NewValue == CheckState.Checked; } if (activeJoints.Contains(changedJoint)) { if (e.NewValue != CheckState.Checked) { activeJoints.Remove(changedJoint); } } else { if (e.NewValue == CheckState.Checked) { activeJoints.Add(changedJoint); } } OpenNIRecordingController video = (videoDataSource.Source as OpenNIRecordingController); if (video != null) { statistics.Calculate(getActiveJoints(), (double)mediaSliderConfidenceThreshold.Value * mediaSliderValueFactor, false, video.CurrentFrame); } }
private void chartErrors_Paint(object sender, PaintEventArgs e) { ChartArea area = chartErrors.ChartAreas[0]; min = (int)area.AxisX.Minimum; max = (int)area.AxisX.Maximum; xPositions.Clear(); xPositions.Add((int)Math.Ceiling(area.AxisX.ValueToPixelPosition(0)) - 1); for (int i = min + 1; i <= max; i++) { xPositions.Add((int)Math.Ceiling(area.AxisX.ValueToPixelPosition(i))); } ynull = (int)area.AxisY.ValueToPixelPosition(0); ymax = (int)area.AxisY.ValueToPixelPosition( area.AxisY.Maximum); // Dispose the former image, as it is not valid any more and also // not needed. if (former_image != null) { former_image.Dispose(); former_image = null; } OpenNIRecordingController rec = videoDataSource.Source as OpenNIRecordingController; if (rec != null) { int CurrentFrame = rec.CurrentFrame; FrameUpdated(CurrentFrame, false, e.Graphics); } }
private void UpdateFrame(object sender, bool handled) { OpenNIRecordingController video = videoDataSource.Source as OpenNIRecordingController; if (video != null) { statistics.UpdateFrame(video.CurrentFrame, getActiveJoints()); } }
private void trackBarVideo_MouseDown(object sender, MouseEventArgs e) { OpenNIRecordingController video_src = videoDisplay.Source as OpenNIRecordingController; if (video_src != null) { video_src.StopPlayback(); } }
/// <summary> /// Updates the value to the current frame position of the /// video source. /// </summary> private void trackBarVideoUpdateValue(object sender, bool handled) { OpenNIRecordingController src = videoDisplay.Source as OpenNIRecordingController; if (src != null && !handled) { trackBarVideo.Value = src.CurrentFrame; } }
private void trackBarVideo_KeyDown(object sender, PreviewKeyDownEventArgs e) { OpenNIRecordingController video_src = videoDisplay.Source as OpenNIRecordingController; // The p key is used for playback control and should hence not // change that state. if (video_src != null && e.KeyData != Keys.P) { video_src.StopPlayback(); } }
private void listBoxResultDataSets_SelectedIndexChanged(object sender, EventArgs e) { listBoxUserResults.ClearSelected(); listBoxUserResults.Items.Clear(); onEvaluationRangeChanged(-1, -1); OpenNIRecordingController source = (videoDataSource.Source as OpenNIRecordingController); if (source != null) { source.AdditionalSkeletonInformation = null; source.AdditionalSkeletonIDs.Clear(); source.RequestUpdate(true); } if (listBoxResultDataSets.SelectedItem == null) { listBoxUserResults.Enabled = false; } else { String resultfilename = Path.Combine(current_take_dir.FullName, (String)listBoxResultDataSets.SelectedItem); try { using (FileStream file = File.Open(resultfilename, FileMode.Open)) { resultDictionary = (ImageDictionary)movementDataSerializer.Deserialize(file); } Dictionary <int, int> userActivities = resultDictionary.GetUserStatistics(null); foreach (int userID in userActivities.Keys) { listBoxUserResults.Items.Add("User " + userID); } if (source != null) { source.AdditionalSkeletonInformation = resultDictionary; onEvaluationRangeChanged(resultDictionary.Keys.Min(), resultDictionary.Keys.Max()); } listBoxUserResults.Enabled = true; } catch (Exception ex) { listBoxUserResults.ClearSelected(); listBoxUserResults.Items.Clear(); listBoxUserResults.Enabled = false; MessageBox.Show(this, "An Error occured loading the results file:\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Cancels the running export task and hides the progress bar. /// </summary> internal void cancelCurrentExport(object sender, EventArgs a) { OpenNIRecordingController exportVideo = videoDisplay.Source as OpenNIRecordingController; if (exportVideo == null) { return; } exportVideo.CancelExport(); exportVideo.ResetExportEventHandlers(); exportForm.Hide(); }
private void trackBarVideo_ValueChanged(object sender, EventArgs e) { if (e is KeyEventArgs || e is MouseEventArgs) { OpenNIRecordingController video_src = videoDisplay.Source as OpenNIRecordingController; if (video_src != null) { video_src.SeekFrame(trackBarVideo.Value); video_src.RequestUpdate(true); } } }
private void listBoxUser_SelectedIndexChanged(object sender, EventArgs e) { OpenNIRecordingController source = (videoDataSource.Source as OpenNIRecordingController); if ((sender as ListBox) != null && (sender as ListBox) == listBoxUserResults && source != null) { source.AdditionalSkeletonIDs.Clear(); if (listBoxUserResults.SelectedItem != null) { int uid_results = parseUserID((String)listBoxUserResults.SelectedItem); source.AdditionalSkeletonIDs.Add(uid_results); } source.RequestUpdate(true); } if (listBoxUserResults.SelectedItem != null && listBoxUserTruth.SelectedItem != null) { // Parse the User IDs from the items. int uid_truth = parseUserID((String)listBoxUserTruth.SelectedItem); int uid_results = parseUserID((String)listBoxUserResults.SelectedItem); // Put the data into the statistics object. statistics.SetData( source.UserLocationInformation, resultDictionary, uid_truth, uid_results, new Statistics.To2DConverter(source.Convert3Dto2D)); // Initialize checkedListBoxBodyParts.Enabled = true; buttonBodyPartsAll.Enabled = true; buttonBodyPartsNone.Enabled = true; mediaSliderConfidenceThreshold.Enabled = true; selectAllBodyJoints(); statistics.Calculate(getActiveJoints(), mediaSliderConfidenceThreshold.Value * mediaSliderValueFactor, true, source.CurrentFrame); } else { clearBodyJointList(); checkedListBoxBodyParts.Enabled = false; buttonBodyPartsAll.Enabled = false; buttonBodyPartsNone.Enabled = false; mediaSliderConfidenceThreshold.Enabled = false; mediaSliderConfidenceThreshold.Value = 0; } }
/// <summary> /// Reports success and tries to generate data index file. /// </summary> private void exportFinished( OpenNIRecordingController sender, DirectoryInfo exportDir, List <int> frames, List <int> userIDs, ImageDictionary exportedFiles2D, ImageDictionary exportedFiles3D, bool ExportRelativePathNames, String export_filename_suffix) { // Report success. lazyInvoke((MethodInvoker) delegate { exportForm.textBoxProgress.Text = "Exporting images finished. Generating data index file..."; }); try { if (exportedFiles2D != null) { using (FileStream write_to = File.OpenWrite( Path.Combine(exportDir.FullName, "Export2D" + export_filename_suffix + ".xml"))) { movementDataSerializer.Serialize(write_to, exportedFiles2D); } } if (exportedFiles3D != null) { using (FileStream write_to = File.OpenWrite( Path.Combine(exportDir.FullName, "Export3D" + export_filename_suffix + ".xml"))) { movementDataSerializer.Serialize(write_to, exportedFiles3D); } } } catch (Exception e) { showException("Error creating data index file: \n" + e.Message); } // Report success. lazyInvoke((MethodInvoker) delegate { exportForm.Hide(); textBoxExport.Text = "Last export successful to folder " + exportDir.FullName; }); sender.ResetExportEventHandlers(); }
private void clearBodyJointList() { statistics.StartBatchPhase(); for (int index = 0; index < checkedListBoxBodyParts.Items.Count; index++) { checkedListBoxBodyParts.SetItemChecked(index, false); } OpenNIRecordingController video = (videoDataSource.Source as OpenNIRecordingController); if (video != null) { statistics.EndBatchPhase(getActiveJoints(), mediaSliderConfidenceThreshold.Value * mediaSliderValueFactor, false, video.CurrentFrame); } }
private void buttonPlay_Click(object sender, EventArgs e) { OpenNIRecordingController video_src = videoDisplay.Source as OpenNIRecordingController; if (video_src != null) { if (buttonPlay.Text.Equals(BUTTON_PLAY_PLAY_TEXT)) { video_src.StartPlayback(); } else { video_src.StopPlayback(); } } }
private void mediaSliderConfidenceThreshold_ValueChanged(object sender, EventArgs e) { OpenNIRecordingController video = (videoDataSource.Source as OpenNIRecordingController); if (video != null) { video.ConfidenceThreshold = (double)mediaSliderConfidenceThreshold.Value * mediaSliderValueFactor; video.RequestUpdate(true); } List <SkeletonJoint> enabledJoints = getActiveJoints(); statistics.Calculate(enabledJoints, (double)mediaSliderConfidenceThreshold.Value * mediaSliderValueFactor, true, video.CurrentFrame); }
/// <summary> /// Reports success and tries to generate data index file. /// </summary> private void exportFinished( OpenNIRecordingController sender, DirectoryInfo exportDir, List<int> frames, List<int> userIDs, ImageDictionary exportedFiles2D, ImageDictionary exportedFiles3D, bool ExportRelativePathNames, String export_filename_suffix) { // Report success. lazyInvoke((MethodInvoker)delegate { exportForm.textBoxProgress.Text = "Exporting images finished. Generating data index file..."; }); try { if (exportedFiles2D != null) { using (FileStream write_to = File.OpenWrite( Path.Combine(exportDir.FullName, "Export2D" + export_filename_suffix + ".xml"))) { movementDataSerializer.Serialize(write_to, exportedFiles2D); } } if (exportedFiles3D != null) { using (FileStream write_to = File.OpenWrite( Path.Combine(exportDir.FullName, "Export3D" + export_filename_suffix + ".xml"))) { movementDataSerializer.Serialize(write_to, exportedFiles3D); } } } catch (Exception e) { showException("Error creating data index file: \n" + e.Message); } // Report success. lazyInvoke((MethodInvoker)delegate { exportForm.Hide(); textBoxExport.Text = "Last export successful to folder " + exportDir.FullName; }); sender.ResetExportEventHandlers(); }
/// <summary> /// Reconfigures the exporting parameters and starts the third part /// of the batch export. /// </summary> private void batchExportPart2Finished( OpenNIRecordingController sender, DirectoryInfo exportDir, List<int> frames, List<int> userIDs, ImageDictionary exportedFiles2D, ImageDictionary exportedFiles3D, bool ExportRelativePathNames, String export_filename_suffix) { // Report success. lazyInvoke((MethodInvoker)delegate { exportForm.textBoxProgress.Text = "Exporting images with skeleton finished (Batch export part 2)." + "Generating data index file..."; }); try { if (exportedFiles2D != null) { using (FileStream write_to = File.OpenWrite( Path.Combine(exportDir.FullName, "Export2D" + export_filename_suffix + ".xml"))) { movementDataSerializer.Serialize(write_to, exportedFiles2D); } } if (exportedFiles3D != null) { using (FileStream write_to = File.OpenWrite( Path.Combine(exportDir.FullName, "Export3D" + export_filename_suffix + ".xml"))) { movementDataSerializer.Serialize(write_to, exportedFiles3D); } } } catch (Exception e) { showException("Error creating data index file: \n" + e.Message); } // Configure for the second export. // Check whether the user selected to do a batch export. OpenNIRecordingController exportVideo = sender; exportVideo.ExportFinished -= batchExportPart2Finished; exportVideo.ExportFinished += exportFinished; // Reset progress bar. lazyInvoke((MethodInvoker)delegate { exportForm.progressBar.Value = 0; exportForm.textBoxProgress.Text = "Initializing batch export part 3..."; }); // Begin exporting. exportVideo.ExportFrames( frames, userIDs, (exportedFiles2D != null), (exportedFiles3D != null), ExportRelativePathNames, true, false, false, false, false, exportDir); }
/// <summary> /// Initializes the export. /// </summary> private void buttonExport_Click(object sender, EventArgs e) { OpenNIRecordingController exportVideo = videoDisplay.Source as OpenNIRecordingController; if (exportVideo == null) { return; } // Stop playback before configuration. exportVideo.StopPlayback(); // Select frames to export List <int> export_frames = new List <int>( Math.Abs(trackBarVideo.LastHighlightedFrame - trackBarVideo.FirstHighlightedFrame)); for (int i = trackBarVideo.FirstHighlightedFrame; i <= trackBarVideo.LastHighlightedFrame; i++) { export_frames.Add(i); } Dictionary <int, int> statistics = exportVideo.GetUserStatistics(export_frames); // Show export configuration dialog. ExportConfiguration configuration_form = new ExportConfiguration( statistics, export_frames); configuration_form.ImageSensorData = exportVideo.ImageOrDepth; configuration_form.DrawBackground = exportVideo.DrawBackground; configuration_form.DrawHighlight = exportVideo.DrawUserHighlight; configuration_form.DrawLabels = exportVideo.DrawUserInformation; configuration_form.DrawSkeleton = exportVideo.DrawSkeletonMesh; configuration_form.ShowDialog(this); if (configuration_form.DialogResult == DialogResult.Cancel) { return; } // Set paralellization event handlers. exportVideo.ExportMadeProgress += exportMadeProgress; exportVideo.ExportFailed += exportFailed; // Check whether the user selected to do a batch export. if (configuration_form.DoBatchExport) { exportVideo.ExportFinished += batchExportPart1Finished; // Configure for the first batch export part and ignore // the corresponding user preferences. configuration_form.ImageSensorData = true; configuration_form.DrawBackground = true; configuration_form.DrawSkeleton = false; configuration_form.DrawHighlight = false; configuration_form.DrawLabels = false; } else { exportVideo.ExportFinished += exportFinished; } // Display progress bar. exportForm.progressBar.Value = 0; exportForm.textBoxProgress.Text = "Initializing export..."; exportForm.Show(this); // Prepare export directory. FileInfo recording = new FileInfo(exportVideo.RecordingFilename); DirectoryInfo recordDir = recording.Directory; DirectoryInfo exportDir = OpenNIImageProvider. GetNewFolderWithHigherIndex(recordDir, EXPORT_DIR_PREFIX, "-"); // Begin exporting. exportVideo.ExportFrames( export_frames, configuration_form.SelectedUsers, configuration_form.AnnotationIn2D, configuration_form.AnnotationIn3D, configuration_form.ExportRelativePathNames, configuration_form.ImageSensorData, configuration_form.DrawBackground, configuration_form.DrawSkeleton, configuration_form.DrawHighlight, configuration_form.DrawLabels, exportDir); }
/// <summary> /// Reconfigures the exporting parameters and starts the second part /// of the batch export. /// </summary> private void batchExportPart1Finished( OpenNIRecordingController sender, DirectoryInfo exportDir, List <int> frames, List <int> userIDs, ImageDictionary exportedFiles2D, ImageDictionary exportedFiles3D, bool ExportRelativePathNames, String export_filename_suffix) { // Report success. lazyInvoke((MethodInvoker) delegate { exportForm.textBoxProgress.Text = "Exporting standard images finished (Batch export part 1)." + "Generating data index file..."; }); try { if (exportedFiles2D != null) { using (FileStream write_to = File.OpenWrite( Path.Combine(exportDir.FullName, "Export2D" + export_filename_suffix + ".xml"))) { movementDataSerializer.Serialize(write_to, exportedFiles2D); } } if (exportedFiles3D != null) { using (FileStream write_to = File.OpenWrite( Path.Combine(exportDir.FullName, "Export3D" + export_filename_suffix + ".xml"))) { movementDataSerializer.Serialize(write_to, exportedFiles3D); } } } catch (Exception e) { showException("Error creating data index file: \n" + e.Message); } // Configure for the second export. // Check whether the user selected to do a batch export. OpenNIRecordingController exportVideo = sender; exportVideo.ExportFinished -= batchExportPart1Finished; exportVideo.ExportFinished += batchExportPart2Finished; // Reset progress bar. lazyInvoke((MethodInvoker) delegate { exportForm.progressBar.Value = 0; exportForm.textBoxProgress.Text = "Initializing batch export part 2..."; }); // Begin exporting. exportVideo.ExportFrames( frames, userIDs, (exportedFiles2D != null), (exportedFiles3D != null), ExportRelativePathNames, true, true, true, false, false, exportDir); }
/// <summary> /// Handle key events. /// </summary> private void MainWindow_KeyUp(object sender, KeyEventArgs e) { if (tabControlVideoSources.SelectedTab == tabPageCapture && kinect != null) { switch (e.KeyData) { case Keys.D: kinect.ImageOrDepth = false; break; case Keys.I: kinect.ImageOrDepth = true; break; case Keys.L: kinect.DrawUserInformation = !kinect.DrawUserInformation; break; case Keys.S: kinect.DrawSkeletonMesh = !kinect.DrawSkeletonMesh; break; case Keys.B: kinect.DrawBackground = !kinect.DrawBackground; break; case Keys.A: kinect.DrawSensorData = !kinect.DrawSensorData; break; case Keys.H: kinect.DrawUserHighlight = !kinect.DrawUserHighlight; break; } } OpenNIRecordingController playback = videoDisplay.Source as OpenNIRecordingController; if (tabControlVideoSources.SelectedTab == tabPageExport && playback != null) { switch (e.KeyData) { case Keys.D: playback.ImageOrDepth = false; playback.RequestUpdate(true); e.SuppressKeyPress = true; break; case Keys.I: playback.ImageOrDepth = true; playback.RequestUpdate(true); e.SuppressKeyPress = true; break; case Keys.S: playback.DrawSkeletonMesh = !playback.DrawSkeletonMesh; playback.RequestUpdate(true); e.SuppressKeyPress = true; //e.Handled = true; break; case Keys.B: playback.DrawBackground = !playback.DrawBackground; playback.RequestUpdate(true); e.SuppressKeyPress = true; break; case Keys.H: playback.DrawUserHighlight = !playback.DrawUserHighlight; playback.RequestUpdate(true); e.SuppressKeyPress = true; break; case Keys.L: playback.DrawUserInformation = !playback.DrawUserInformation; playback.RequestUpdate(true); e.SuppressKeyPress = true; break; case Keys.A: playback.DrawSensorData = !playback.DrawSensorData; playback.RequestUpdate(true); e.SuppressKeyPress = true; break; case Keys.M: buttonMarkFrame.PerformClick(); e.SuppressKeyPress = true; break; case Keys.E: buttonExport.PerformClick(); e.SuppressKeyPress = true; break; case Keys.R: buttonResetMarkers.PerformClick(); e.SuppressKeyPress = true; break; case Keys.P: buttonPlay.PerformClick(); e.SuppressKeyPress = true; break; case Keys.Left: case Keys.Right: case Keys.PageDown: case Keys.PageUp: if (!trackBarVideo.Focused) { trackBarVideo.Focus(); } break; } } }