public void ShutdownSensor() { if (kinect != null) { //The "new" syntax is sort of odd, but these really do remove the handlers from the specified events kinect.ColorFrameReady -= new EventHandler <ColorImageFrameReadyEventArgs>(kinect_ColorFrameReady); kinect.DepthFrameReady -= new EventHandler <DepthImageFrameReadyEventArgs>(kinect_DepthFrameReady); kinect.SkeletonFrameReady -= new EventHandler <SkeletonFrameReadyEventArgs>(kinect_SkeletonFrameReady); interactStream.InteractionFrameReady -= new EventHandler <InteractionFrameReadyEventArgs>(interactStream_InteractionFrameReady); if (updateTimer != null) { updateTimer.Stop(); updateTimer.Elapsed -= updateTimer_Elapsed; updateTimer.Dispose(); } interactStream.Dispose(); interactStream = null; if (kinect.AudioSource != null) { kinect.AudioSource.Stop(); } kinect.Stop(); } }
protected virtual void Dispose(bool disposing) { if (disposing) { _sensor.DepthFrameReady -= SensorOnDepthFrameReady; _sensor.SkeletonFrameReady -= SensorOnSkeletonFrameReady; _interactionStream.InteractionFrameReady -= InteractionStreamOnInteractionFrameReady; _interactionStream.Dispose(); } }
public void Evaluate(int SpreadMax) { if (this.FInvalidateConnect) { if (this.FInRuntime.PluginIO.IsConnected) { stream = new InteractionStream(this.FInRuntime[0].Runtime, new InteractionClientTest()); stream.InteractionFrameReady += stream_InteractionFrameReady; this.runtime = this.FInRuntime[0]; this.runtime.SkeletonFrameReady += runtime_SkeletonFrameReady; this.runtime.DepthFrameReady += this.runtime_DepthFrameReady; } else { if (stream != null) { this.runtime.SkeletonFrameReady -= runtime_SkeletonFrameReady; this.runtime.DepthFrameReady -= this.runtime_DepthFrameReady; stream.InteractionFrameReady -= stream_InteractionFrameReady; stream.Dispose(); stream = null; this.runtime = null; } } this.FInvalidateConnect = false; } List <UserInfo> infs = new List <UserInfo>(); for (int i = 0; i < this.infos.Length; i++) { if (this.infos[i] != null) { if (this.infos[i].SkeletonTrackingId != 0) { infs.Add(this.infos[i]); } } } this.FOutSkelId.SliceCount = infs.Count; this.FOutUI.SliceCount = infs.Count; for (int i = 0; i < infs.Count; i++) { UserInfo ui = infs[i]; this.FOutSkelId[i] = ui.SkeletonTrackingId; this.FOutUI[i] = ui; } }
public void ShutdownSensor() { if (kinect != null) { lock (kinect) { //The "new" syntax is sort of odd, but these really do remove the handlers from the specified events kinect.ColorFrameReady -= kinect_ColorFrameReady; kinect.DepthFrameReady -= kinect_DepthFrameReady; kinect.SkeletonFrameReady -= kinect_SkeletonFrameReady; interactStream.InteractionFrameReady -= interactStream_InteractionFrameReady; if (updateTimer != null) { updateTimer.Stop(); updateTimer.Elapsed -= updateTimer_Elapsed; updateTimer.Dispose(); } interactStream.Dispose(); interactStream = null; if (kinect.AudioSource != null) { if (audioStream != null) { audioStream.Close(); audioStream.Dispose(); } kinect.AudioSource.Stop(); } kinect.ColorStream.Disable(); kinect.DepthStream.Disable(); kinect.SkeletonStream.Disable(); kinect.Stop(); kinect.Dispose(); kinect = null; } } }
/// <summary> /// Instantiates a new InteractionStream, feeds this InteractionStream with Skeleton- and DepthData and subscribes to the InteractionFrameReady event. /// </summary> /// <param name="kinectSensor">The Kinect sensor passed to the interaction stream instance.</param> /// <param name="interactionClient">The interaction client passed to the interaction stream instance.</param> /// <returns>An UserInfo stream that contains an action that disposes the interaction stream when the observable is disposed.</returns> public static IObservable <UserInfo[]> GetUserInfoObservable(this KinectSensor kinectSensor, IInteractionClient interactionClient) { if (kinectSensor == null) { throw new ArgumentNullException("kinect"); } if (interactionClient == null) { throw new ArgumentNullException("interactionClient"); } if (!kinectSensor.DepthStream.IsEnabled) { throw new InvalidOperationException("The depth stream is not enabled, but mandatory."); } if (!kinectSensor.SkeletonStream.IsEnabled) { throw new InvalidOperationException("The skeleton stream is not enabled, but mandatory."); } return(Observable.Create <UserInfo[]>(observer => { var stream = new InteractionStream(kinectSensor, interactionClient); var obs = kinectSensor.GetAllFramesReadyObservable() .SelectStreams((_, __) => Tuple.Create(_.Timestamp, __.Timestamp)) .Subscribe(_ => { stream.ProcessSkeleton(_.Item3, kinectSensor.AccelerometerGetCurrentReading(), _.Item4.Item1); stream.ProcessDepth(_.Item2, _.Item4.Item2); }); stream.GetInteractionFrameReadyObservable() .SelectUserInfo() .Subscribe(_ => observer.OnNext(_)); return new Action(() => { obs.Dispose(); stream.Dispose(); }); })); }
/// <summary> /// Fermeture des flux /// </summary> internal void Close() { // Fermeture et arrêt couleur Sensor.ColorFrameReady -= EventColorFrameReady; Sensor.ColorStream.Disable(); // Fermeture et arrêt profondeur Sensor.DepthFrameReady -= EventDepthFrameReady; Sensor.DepthStream.Disable(); // Fermeture et arrêt squelette Sensor.SkeletonFrameReady -= EventSkeletonFrameReady; Sensor.SkeletonStream.Disable(); // Fermeture et arrêt interaction interactionStream.InteractionFrameReady -= EventInteractionFrameReady; interactionStream.Dispose(); canvas.Children.Clear(); }