예제 #1
0
        /// <summary>
        /// Runs every time our 3D coordinates are ready.
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="a">Skeleton 3Ddata Coord Event Args</param>
        private void NuiSkeleton3DDataCoordReady(object sender, Skeleton3DDataCoordEventArgs a)
        {
            #if false
            //Assume that capture equal number of frames for all joints!
            var iterator = _skeletonTimeSequence.GetEnumerator();
            //Must MoveNext to get first element.
            iterator.MoveNext();
            int numberOfFramesCaptured = iterator.Current.Value.Count;
            //currentBufferFrame.Text = numberOfFramesCaptured.ToString();
            bool test = false;

            // We need a sensible number of frames before we start attempting to match gestures against remembered sequences
            if (numberOfFramesCaptured > MinimumFrames && _capturing == false)
            {
                string s = _dtw.Recognize(_skeletonTimeSequence);
                //results.Text = s;
                if (!s.Contains("__UNKNOWN"))
                {
                    // There was a match so reset the buffer
                    //_video = new ArrayList();
                    RemoveAllFramesSkeletonTimeSequence();
                    if (GestureDone != null)
                        GestureDone(this, new GestureEventArgs(s));
                    test = true;
                    nogesture_ = false;
                }
                else
                {

                    if (!nogesture_ && NoGestureDone != null)
                        NoGestureDone(this, new EventArgs());
                    nogesture_ = true;
                }
            }
            //Get current number of frames again. Hacky.
            iterator = _skeletonTimeSequence.GetEnumerator();
            iterator.MoveNext();
            numberOfFramesCaptured = iterator.Current.Value.Count;
            nof_ = numberOfFramesCaptured;

            // Ensures that we remember only the last x frames
            if (numberOfFramesCaptured > BufferSize)
            {
                // If we are currently capturing and we reach the maximum buffer size then automatically store
                if (_capturing)
                {
                    // FIXED: no capturing mode for Kynapsee
                    //DtwStoreClick(null, null);
                    if (CaptureEnd != null)
                        CaptureEnd(this, new EventArgs());
                }
                else
                {
                    // Remove the first frame in the buffer
                    //_video.RemoveAt(0);
                    if (test)
                    {
                        throw new Exception();
                    }
                    RemoveFirstFrameSkeletonTimeSequence();
                }
            }

            // Decide which skeleton frames to capture. Only do so if the frames actually returned a number.
            // For some reason my Kinect/PC setup didn't always return a double in range (i.e. infinity) even when standing completely within the frame.
            // TODO Weird. Need to investigate this
            //if (!double.IsNaN(a.GetPoint(0).X))
            var snapShot = a.GetSkeletonSnapshot();
            var snapShotIterator = snapShot.GetEnumerator();
            snapShotIterator.MoveNext();
            if (!double.IsNaN(snapShotIterator.Current.Value.X))
            {
                // Optionally register only 1 frame out of every n
                _flipFlop = (_flipFlop + 1) % Ignore;
                if (_flipFlop == 0)
                {
                    //_video.Add(a.GetCoords());
                    AppendToSkeletonTimeSequence(snapShot);
                }
            }

            // Update the debug window with Sequences information
            //dtwTextOutput.Text = _dtw.RetrieveText();
            #endif
        }
예제 #2
0
        private void NuiSkeleton3DDataCoordReady(object sender, Skeleton3DDataCoordEventArgs a)
        {
            //Assume that capture equal number of frames for all joints!
            var iterator = skeletonTimeSequence_.GetEnumerator();
            //Must MoveNext to get first element.
            iterator.MoveNext();
            int numberOfFramesCaptured = iterator.Current.Value.Count;
            //currentBufferFrame.Text = numberOfFramesCaptured.ToString();

            if (FrameStart != null)
                FrameStart(this, new NuiEventArgs(null, numberOfFramesCaptured));

            // We need a sensible number of frames before we start attempting to match gestures against remembered sequences
            if (numberOfFramesCaptured > MinimumFrames && !capturing_)
            {
                Gesture s = dtw_.Recognize(skeletonTimeSequence_);

                if (s != null)
                {
                    if (GestureDone != null)
                        GestureDone(this, new NuiEventArgs(s, numberOfFramesCaptured));
                    RemoveAllFramesSkeletonTimeSequence();
                    numberOfFramesCaptured = 0;
                }
                else
                {
                    /*
                    if (!nogesture_ && NoGestureDone != null)
                        NoGestureDone(this, new EventArgs());
                    nogesture_ = true;*
                     */
                }
            }
            //Get current number of frames again. Hacky.
            //iterator = _skeletonTimeSequence.GetEnumerator();
            //iterator.MoveNext();
            //numberOfFramesCaptured = iterator.Current.Value.Count;
            //nof_ = numberOfFramesCaptured;

            if (capturing_ && CaptureProgress != null)
            {
                CaptureProgress(this, new NuiEventArgs(null, numberOfFramesCaptured));
            }

            // Ensures that we remember only the last x frames
            if (numberOfFramesCaptured >= BufferSize)
            {
                // If we are currently capturing and we reach the maximum buffer size then automatically store
                if (capturing_)
                {
                    // FIXED: no capturing mode for Kynapsee
                    //DtwStoreClick(null, null);
                    if (CaptureEnd != null)
                        CaptureEnd(this, new NuiEventArgs(null, numberOfFramesCaptured));
                    capturing_ = false;
                    RemoveAllFramesSkeletonTimeSequence();
                }
                else
                {
                    RemoveFirstFrameSkeletonTimeSequence();
                }
            }

            // Decide which skeleton frames to capture. Only do so if the frames actually returned a number.
            // For some reason my Kinect/PC setup didn't always return a double in range (i.e. infinity) even when standing completely within the frame.
            // TODO Weird. Need to investigate this
            //if (!double.IsNaN(a.GetPoint(0).X))
            var snapShot = a.GetSkeletonSnapshot();
            var snapShotIterator = snapShot.GetEnumerator();
            snapShotIterator.MoveNext();
            if (!double.IsNaN(snapShotIterator.Current.Value.X))
            {
                // Optionally register only 1 frame out of every n
                flipFlop_ = (flipFlop_ + 1) % Ignore;
                if (flipFlop_ == 0)
                {
                    AppendToSkeletonTimeSequence(snapShot);
                }
            }
        }