private void Stream_BodyFrame_Click(object sender, RoutedEventArgs e) { this.btnSetupKinect2KitServer.IsEnabled = false; this.btnStartStopStreaming.IsEnabled = false; if (!Kinect2Kit.TrySetServerEndPoint(serverAddress, serverPort)) { MessageBox.Show(this, "The server is not available. Is it running?", "Kinect2Kit notification"); this.StatusText = "The server is not avaialble!!"; this.btnSetupKinect2KitServer.IsEnabled = true; this.btnStartStopStreaming.IsEnabled = false; return; } this.streaming = !this.streaming; if (this.streaming) { this.StatusText = "Streaming data to the server."; this.btnSetupKinect2KitServer.IsEnabled = false; this.btnStartStopStreaming.Content = "Stop"; this.btnStartStopStreaming.IsEnabled = true; } else { this.StatusText = "Stopped streaming data to the server."; this.btnSetupKinect2KitServer.IsEnabled = true; this.btnStartStopStreaming.Content = "Start"; this.btnStartStopStreaming.IsEnabled = true; } }
private async void Track_Start_Click(object sender, RoutedEventArgs e) { // Disable File this.MenuItem_File_Open.IsEnabled = false; this.Button_File_Open.Visibility = Visibility.Collapsed; SetupSessionDialog setupSession = new SetupSessionDialog(); setupSession.Owner = Application.Current.MainWindow; setupSession.WindowStartupLocation = WindowStartupLocation.CenterOwner; if (setupSession.ShowDialog() == true) { // Disable Start while waiting from the sever this.MenuItem_Track_Start.IsEnabled = false; this.Button_Track_Start.Visibility = Visibility.Collapsed; string sessionName = setupSession.entryName.Text; this.StatusText = String.Format("Kinect2Kit server @ {1} was starting session {1}.", Kinect2Kit.ServerEndpoint, sessionName); Kinect2KitSimpleResponse resp = await Kinect2Kit.StartSessionAsync(sessionName); if (resp.IsSuccessful) { this.MenuItem_Track_Pause.IsEnabled = true; this.Button_Track_Pause.Visibility = Visibility.Visible; this.MenuItem_Track_Stop.IsEnabled = true; this.Button_Track_Stop.Visibility = Visibility.Visible; this.StatusText = String.Format("Kinect2Kit server @ {0} started session {1}.", Kinect2Kit.ServerEndpoint, sessionName); // Start tracking task this.trackingTaskTokenSource = new CancellationTokenSource(); this.trackingTask = Task.Run(() => this.Track(this.trackingTaskTokenSource.Token), this.trackingTaskTokenSource.Token); } else { // Re-enable Start this.MenuItem_Track_Start.IsEnabled = true; this.Button_Track_Start.Visibility = Visibility.Visible; // Re-enable File this.MenuItem_File_Open.IsEnabled = true; this.Button_File_Open.Visibility = Visibility.Visible; this.StatusText = String.Format("Kinect2Kit session {0} not started. Message: {1}.", sessionName, resp.ServerMessage); } } else { // Re-enable File this.MenuItem_File_Open.IsEnabled = true; this.Button_File_Open.Visibility = Visibility.Visible; this.StatusText = "Kinect2Kit session not started."; } }
private async void StopTrackingTask() { this.trackingTaskTokenSource.Cancel(); try { this.trackingTask.Wait(); Kinect2KitSimpleResponse stopResp = await Kinect2Kit.StopSessionAsync(); } catch (Exception) { System.Diagnostics.Debug.WriteLine("Exception when stopping task."); } finally { this.trackingTaskTokenSource.Dispose(); } }
private void File_Open_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { this.StatusText = "Loading Kinect2Kit setup..."; string setupFile = openFileDialog.FileName; if (!Kinect2Kit.TryLoadSetup(setupFile)) { MessageBox.Show(this, "The server is not available. Is it running?", "Kinect2Kit"); this.StatusText = "Kinect2Kit setup was not loaded. The server is not available."; return; } // TRACK this.Menu_Track.IsEnabled = true; this.MenuItem_Track_Start.Visibility = Visibility.Visible; this.Button_Track_Start.Visibility = Visibility.Visible; // VIEW foreach (Kinect2KitClientSetup view in Kinect2Kit.KinectClients) { MenuItem kinectFOVMenuItem = new MenuItem(); kinectFOVMenuItem.Header = view.Name; kinectFOVMenuItem.Click += this.KinectFOVMenuitem_Click; this.Menu_View.Items.Add(kinectFOVMenuItem); this.kinectFOVMenuItems.Add(kinectFOVMenuItem); } // Select first view MenuItem firstKinectFOV = this.kinectFOVMenuItems.ElementAt(0); firstKinectFOV.IsChecked = true; this.selectedKinectFOV = firstKinectFOV; this.StatusText = String.Format("Kinect2Kit setup loaded from {0}.", setupFile); } else { this.StatusText = "Kinect2Kit setup not loaded."; } }
private async void Track(CancellationToken ct) { // calibration Kinect2KitSimpleResponse resp = await Kinect2Kit.StartCalibrationAsync(); if (resp.IsSuccessful) { this.StatusText = String.Format("Kinect2Kit server @ {0} started calibration.", Kinect2Kit.ServerEndpoint); try { while (true) { ct.ThrowIfCancellationRequested(); if (this.trackingTaskPaused) { this.StatusText = "Tracking paused."; continue; } Kinect2KitCalibrationResponse calibrationResp = await Kinect2Kit.GetCalibrationStatusAsync(); if (calibrationResp.Finished) { this.StatusText = String.Format("Kinect2Kit server @ {0} finished calibration.", Kinect2Kit.ServerEndpoint); break; } else if (calibrationResp.AcquiringFrames) { if (calibrationResp.HasError) { this.StatusText = String.Format("Kinect2Kit server @ {0} was acquring frames. Error: {1}.", Kinect2Kit.ServerEndpoint, calibrationResp.Error); } else { this.StatusText = String.Format("Kinect2Kit server @ {0} was acquring frames. Required: {1}, Remained: {2}.", Kinect2Kit.ServerEndpoint, calibrationResp.RequiredFrames, calibrationResp.RemainedFrames); } } else if (calibrationResp.ResolvingFrames) { this.StatusText = String.Format("Kinect2Kit server @ {0} was resolving frames.", Kinect2Kit.ServerEndpoint); } await Task.Delay(100); // slow down } } catch (OperationCanceledException) { return; } } // tracking resp = await Kinect2Kit.StartTrackingAsync(); if (resp.IsSuccessful) { this.StatusText = String.Format("Kinect2Kit server @ {0} started tracking.", Kinect2Kit.ServerEndpoint); try { while (true) { ct.ThrowIfCancellationRequested(); if (this.trackingTaskPaused) { this.StatusText = "Tracking paused."; continue; } Kinect2KitTrackingResponse trackingResp = await Kinect2Kit.GetTrackingResultAsync(); if (trackingResp.IsSuccessful) { this.TrackingResultArrived(trackingResp.Timestamp, trackingResp.Perspectives); } } } catch (OperationCanceledException) { this.StatusText = "Tracking stopped."; this.ClearTrackingImage(); return; } } }
private async void SendBodyFrame(double timestamp, Body[] bodies) { Kinect2KitSimpleResponse resp = await Kinect2Kit.StreamBodyFrame(timestamp, bodies); this.StatusText = String.Format("Streaming BodyFrame(timestamp: {0}) to Kinect2Kit server @ {1}, Response: {2} ", timestamp, Kinect2Kit.ServerEndpoint, resp.ServerMessage); }