Provides an interface to a single Kinect sensor with IObservables for all of its events
        private SkeletonTracking(KinectSensor sensor)
        {
            Contract.Requires(sensor != null);

            mySensor = sensor;
            var skeletonFrames =
                mySensor
                .SkeletonFrames
                .Select(sf => sf.SkeletonFrame);

            //skeletonFrames
            //    .Sample(TimeSpan.FromSeconds(5.0))
            //    .Subscribe(PrintSkeletonFrames);

            _SkeletonPresent = skeletonFrames
                .Select(sf => sf.Skeletons.Any(skel => skel.TrackingState != SkeletonTrackingState.NotTracked))
                .DistinctUntilChanged();

            mySkeletonTracker = new SkeletonDispatcher(skeletonFrames.Select(sf => sf.Skeletons));
        }
示例#2
0
        private static void AddRuntimeOptions(KinectSensor sensor, RuntimeOptions options)
        {
            Contract.Requires(sensor != null);

            sensor.myOptions |= options;

            sensor.Device.Uninitialize();
            sensor.Device.Initialize(sensor.myOptions);
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonTracking"/> class using the Kinect sensor at the specified index.
 /// </summary>
 /// <param name="sensorIndex">Index of the Kinect sensor to use.</param>
 public SkeletonTracking(int sensorIndex)
     : this(KinectSensor.Start(RuntimeOptions.UseSkeletalTracking, sensorIndex))
 {
     Contract.Requires(sensorIndex >= 0 && sensorIndex < Runtime.Kinects.Count);
 }
示例#4
0
        /// <summary>
        /// Starts the Kinect with the specified options.
        /// </summary>
        /// <param name="options">The options to run the Kinect with as a set of flags.</param>
        /// <param name="kinectIndex">Index of the Kinect device you want to start, unless you have multiple Kinects attached you want to use the default value of 0.</param>
        /// <returns>A sensor instance which will allow you to operate on the Kinect that was just started.</returns>
        public static KinectSensor Start(RuntimeOptions options, int kinectIndex = 0)
        {
            Contract.Requires(0 < Runtime.Kinects.Count);
            Contract.Requires(kinectIndex >= 0 && kinectIndex < Runtime.Kinects.Count);
            Contract.Ensures(Contract.Result<KinectSensor>() != null && ReferenceEquals(Contract.Result<KinectSensor>().Device, Runtime.Kinects[kinectIndex]));

            lock (ourKinectSensors)
            {
                if (ourKinectSensors[kinectIndex] != null)
                    AddRuntimeOptions(ourKinectSensors[kinectIndex], options);
                else
                    ourKinectSensors[kinectIndex] = new KinectSensor(kinectIndex, options);

                return ourKinectSensors[kinectIndex];
            }
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonTracking"/> class using the default Kinect sensor.
 /// </summary>
 public SkeletonTracking()
     : this(KinectSensor.Start(RuntimeOptions.UseSkeletalTracking))
 {
 }