Example #1
0
        /// <summary>
        /// Runs after the window is loaded
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">Routed Event Args</param>
        public void Init()
        {
            _nui = new Runtime();

            try
            {
                _nui.Initialize(RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor | RuntimeOptions.UseDepthAndPlayerIndex);
            }
            catch (InvalidOperationException)
            {
                //System.Windows.MessageBox.Show("Runtime initialization failed. Please make sure Kinect device is plugged in.");

                throw;
            }

            //try
            //{
            //    _nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
            //    _nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
            //}
            //catch (InvalidOperationException)
            //{
            //    //System.Windows.MessageBox.Show(
            //    //    "Failed to open stream. Please make sure to specify a supported image type and resolution.");
            //    throw;
            //}

            _lastTime = DateTime.Now;

            _dtw = new DtwGestureRecognizer(_vectorDimension, _jointsTracked, _sequenceSimilarityThreshold, _finalPositionThreshold, _maxSlope, _minGestureLength);
            RemoveAllFramesSkeletonTimeSequence();

            // If you want to see the depth image and frames per second then include this
            // I'mma turn this off 'cos my 'puter is proper slow
            //_nui.DepthFrameReady += NuiDepthFrameReady;

            //_nui.SkeletonFrameReady += NuiSkeletonFrameReady;
            _nui.SkeletonFrameReady += SkeletonExtractSkeletonFrameReady;

            // If you want to see the RGB stream then include this
            //_nui.VideoFrameReady += NuiColorFrameReady;

            //Skeleton3DDataExtract.Skeleton3DDataCoordReady += NuiSkeleton3DDataCoordReady;

            // Update the debug window with Sequences information
            //dtwTextOutput.Text = _dtw.RetrieveText();

            Debug.WriteLine("Finished Window Loading");
        }
Example #2
0
        /// <summary>
        /// Creates a new provider on the first found NUI device.
        /// </summary>
        /// <param name="gestures">Gesture model.</param>
        /// <param name="enableColor">Enable color capture.</param>
        /// <param name="enableDepth">Enable depth capture.</param>
        public Provider(GestureSet gestures = null, bool enableColor = false, bool enableDepth = false)
        {
            try
            {

                // limititation: we take the first found Kinect.
                // todo: let the user choose?
                nui_ = Runtime.Kinects[0];

                nui_.Initialize(RuntimeOptions.UseSkeletalTracking
                                | (enableColor ? RuntimeOptions.UseColor : 0)
                                | (enableDepth ? RuntimeOptions.UseDepthAndPlayerIndex : 0));

            }
            catch (Exception)
            {
                throw new InvalidOperationException("There is no connected NUI device.");
            }

            dtw_ = new DtwGestureRecognizer(VectorDimension, JointsTracked, SequenceSimilarityThreshold, FinalPositionThreshold, MaxSlope, MinGestureLength);
            RemoveAllFramesSkeletonTimeSequence();

            if (gestures != null)
            {
                foreach (var gesture in gestures.Gestures)
                {
                    dtw_.AddOrUpdate(gesture);
                }
            }

            nui_.SkeletonFrameReady += SkeletonExtractSkeletonFrameReady;
            sde_.Skeleton3DDataCoordReady += NuiSkeleton3DDataCoordReady;
        }