/// <summary> /// Frees all memory associated with the FusionImageFrame. /// </summary> /// <param name="disposing">Whether the function was called from Dispose.</param> protected virtual void Dispose(bool disposing) { if (this.disposed) { return; } this.disposed = true; KinectSensorChooser.Stop(); StopKinect(); if (_kinectWorkQueue != null) { _kinectWorkQueue.Dispose(); _kinectWorkQueue = null; } if (FusionManager != null) { FusionManager.Dispose(); FusionManager = null; } }
private void StartKinect(KinectSensor newSensor) { try { newSensor.ColorStream.Enable(DefaultColorImageFormat); newSensor.DepthStream.Enable(DefaultDepthImageFormat); try { // This will throw on non Kinect For Windows devices. newSensor.DepthStream.Range = DepthRange.Near; newSensor.SkeletonStream.EnableTrackingInNearRange = true; } catch (InvalidOperationException) { newSensor.DepthStream.Range = DepthRange.Default; newSensor.SkeletonStream.EnableTrackingInNearRange = false; } newSensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated; var smoothParams = new TransformSmoothParameters() { Smoothing = 0.8f, Correction = 0.2f, Prediction = 0.5f, JitterRadius = 0.10f, MaxDeviationRadius = 0.04f }; newSensor.SkeletonStream.Enable(smoothParams); newSensor.AllFramesReady += KinectSensorOnAllFramesReady; _elevationAngle = newSensor.ElevationAngle; RaisePropertyChanged(ElevationAnglePropertyName); this.KinectSensor = newSensor; this.rawFrameCount = 0; //TODO cleanup old voice command _voiceCommand = new VoiceCommand(newSensor); _voiceCommand.IsListeningChanged += (s, e) => { this.IsListening = _voiceCommand.IsListening; if (this.IsListening) { VoiceHeard = "Listening..."; } }; _voiceCommand.FusionPause += (s, e) => { if (FusionManager.IsIntegrationPaused) { FusionManager.IsIntegrationPaused = false; FusionManager.RotationRateInDegrees = 0; FusionManager.CurrentRotationDegrees = 0; } else { FusionManager.IsIntegrationPaused = true; FusionManager.RotationRateInDegrees = 3; } VoiceHeard = "Heard: Fusion Pause"; }; _voiceCommand.FusionReset += (s, e) => { ResetCommand.Execute(null); if (FusionManager != null) { FusionManager.IsIntegrationPaused = false; FusionManager.RotationRateInDegrees = 0; FusionManager.CurrentRotationDegrees = 0; } VoiceHeard = "Heard: Fusion Reset"; }; _voiceCommand.FusionStart += (s, e) => { ResetCommand.Execute(null); if (FusionManager != null) { FusionManager.IsIntegrationPaused = false; FusionManager.RotationRateInDegrees = 0; FusionManager.CurrentRotationDegrees = 0; } VoiceHeard = "Heard: Fusion Start"; }; if (FusionManager != null) { FusionManager.Dispose(); FusionManager = null; } FusionManager = new FusionManager(KinectSensor); } catch (InvalidOperationException) { // This exception can be thrown when we are trying to // enable streams on a device that has gone away. This // can occur, say, in app shutdown scenarios when the sensor // goes away between the time it changed status and the // time we get the sensor changed notification. // // Behavior here is to just eat the exception and assume // another notification will come along if a sensor // comes back. } }