Beispiel #1
0
        private void NuiSkeleton2DdataCoordReady(object sender, Skeleton2DdataCoordEventArgs a)
        {
            if (_kinectHandler == null || _seqCoords == null || _dtw == null)
            {
                return;
            }

            if (_seqCoords.Count > MINIMUM_FRAMES && !_isRecording && _isRecognizing)
            {
                ////Console.Out.WriteLine("No of frames: " + seqCoords.Count);
                if (_dtw != null)
                {
                    var g = _dtw.Recognize(_seqCoords, _ctxt);


                    if (_recTimer != null && (g != null || _recTimer.ElapsedMilliseconds > 4000))
                    {
                        _isRecognizing = false;
                        _seqCoords.Clear();


                        if (g != null && (!g.Name.Equals("__UNKNOWN") || _recTimer.ElapsedMilliseconds > 4000))
                        {
                            _kinectHandler.GestureRecognitionCompleted(g.Name);
                        }
                    }
                }
            }

            if (_isRecording)
            {
                _kinectHandler.RecordingCountdownEvent(_seqCoords.Count);
            }

            if (_seqCoords.Count > BUFFER_SIZE)
            {
                lock (this) {
                    if (_isRecording && _currentGesture != null)
                    {
                        _isRecording = false;

                        if (_dtw != null)
                        {
                            _dtw.AddOrUpdate(_seqCoords, _currentGesture);
                        }
                        _seqCoords.Clear();
                        _kinectHandler.GestureRecordCompleted(_currentGesture.Name, _currentGesture.Context);
                        _currentGesture = null;
                    }
                    else
                    {
                        _seqCoords.RemoveAt(0);
                    }
                }
            }

            if (a == null || Double.IsNaN(a.GetPoint(0).X))
            {
                return;
            }
            // Optionally register only 1 frame out of every n
            _flipFlop = (_flipFlop + 1) % IGNORE;
            if (_flipFlop == 0)
            {
                _seqCoords.Add(a.GetCoords());
            }
        }