Last active
August 29, 2015 13:56
-
-
Save lothrop/9008401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IObservable<double> pos | |
| = from joint in joints | |
| select | |
| (joint[JointType.FootLeft].Position.Y | |
| + joint[JointType.FootRight].Position.Y) / 2.0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IObservable<JointCollection> joints | |
| = from sd in skeletons | |
| let tracked = sd.SingleOrDefault( | |
| s => s.TrackingState == SkeletonTrackingState.Tracked) | |
| where tracked != null | |
| select tracked.Joints; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq; | |
| using System.Reactive.Linq; | |
| using Microsoft.Kinect; | |
| namespace JumpAndRun | |
| { | |
| public static class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var kinect = KinectSensor.KinectSensors.Single(); | |
| Console.WriteLine(kinect.DeviceConnectionId); | |
| var skeletonFrames = Observable.FromEventPattern | |
| <SkeletonFrameReadyEventArgs>( | |
| h => kinect.SkeletonFrameReady += h, | |
| h => kinect.SkeletonFrameReady -= h); | |
| var skeletons = skeletonFrames.Select(sf => | |
| { | |
| using (var frame = sf.EventArgs.OpenSkeletonFrame()) | |
| { | |
| var sd = new Skeleton[frame.SkeletonArrayLength]; | |
| frame.CopySkeletonDataTo(sd); | |
| return sd; | |
| } | |
| }); | |
| var joints = from sd in skeletons | |
| let tracked = sd.SingleOrDefault( | |
| s => s.TrackingState == SkeletonTrackingState.Tracked) | |
| where tracked != null | |
| select tracked.Joints; | |
| var pos = from joint in joints | |
| select | |
| (joint[JointType.FootLeft].Position.Y | |
| + joint[JointType.FootRight].Position.Y) / 2.0; | |
| var jumped = from p in pos.Buffer(TimeSpan.FromSeconds(1), | |
| TimeSpan.FromMilliseconds(200)) | |
| where p.Count() > 2 | |
| let lowThreshold = p.Max() - 0.5 | |
| select p.First() < lowThreshold && p.Last() < lowThreshold | |
| ? "jumped" | |
| : "didn't jump"; | |
| var jumpedChanged = jumped.DistinctUntilChanged(); | |
| var jumps = from j in jumpedChanged where j == "jumped" select j; | |
| jumps.Subscribe(Console.WriteLine); | |
| kinect.SkeletonStream.Enable(); | |
| kinect.Start(); | |
| Console.ReadLine(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IObservable<string> jumped | |
| = from p in pos.Buffer(TimeSpan.FromSeconds(1), | |
| TimeSpan.FromMilliseconds(200)) | |
| where p.Count() > 2 | |
| let lowThreshold = p.Max() - 0.5 | |
| select p.First() < lowThreshold && p.Last() < lowThreshold | |
| ? "jumped" | |
| : "didn't jump"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IObservable<string> jumpedChanged = jumped.DistinctUntilChanged(); | |
| IObservable<string> jumps = from j in jumpedChanged where j == "jumped" select j; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jumps.Subscribe(Console.WriteLine); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kinect.SkeletonStream.Enable(); | |
| kinect.Start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| KinectSensor kinect = KinectSensor.KinectSensors.Single(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IObservable<EventPattern<SkeletonFrameReadyEventArgs>> skeletonFrames | |
| = Observable.FromEventPattern<SkeletonFrameReadyEventArgs>( | |
| h => kinect.SkeletonFrameReady += h, | |
| h => kinect.SkeletonFrameReady -= h); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IObservable<Skeleton[]> skeletons = skeletonFrames.Select(sf => | |
| { | |
| using (SkeletonFrame frame = sf.EventArgs.OpenSkeletonFrame()) | |
| { | |
| Skeleton[] sd = new Skeleton[frame.SkeletonArrayLength]; | |
| frame.CopySkeletonDataTo(sd); | |
| return sd; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment