public void AddOrUpdate(ArrayList seq, Gesture g)
 {
     AddOrUpdate(seq, g.Name, g.Context, true);
 }
        /// <summary>
        /// Add a seqence with a label to the known sequences library.
        /// The gesture MUST start on the first observation of the sequence and end on the last one.
        /// Sequences may have different lengths.
        /// </summary>
        /// <param name="seq">The sequence</param>
        /// <param name="lab">Sequence name</param>
        /// <param name="ctxt"> </param>
        /// <param name="saveToFile"> </param>
        public void AddOrUpdate(ArrayList seq, string lab, string ctxt, bool saveToFile)
        {
            if (seq.Count == 0) return;
                // First we check whether there is already a recording for this label. If so overwrite it, otherwise add a new entry
                var existingIndex = -1;

                if(_gestures == null)
                {
                    _gestures = new ArrayList();
                }

            for (var i = 0; i < _gestures.Count; i++)
                {
                    var gesture = (Gesture) _gestures[i];

                    if (gesture != null && lab.Equals(gesture.Name) && ctxt.Equals(gesture.Context))
                    {
                        existingIndex = i;
                    }
                }

                Gesture g;
                // If we have a match then remove the entries at the existing index to avoid duplicates. We will add the new entries later anyway
                if (existingIndex >= 0)
                {
                    Log.Info("Found existing gesture, updating sequence.");
                    g = ((Gesture)_gestures[existingIndex]);
                    g.Sequence = seq;
                }
                else
                {
                    Log.Info("This is a new gesture, saving.");
                    g = new Gesture(lab, ctxt, seq);
                    _gestures.Add(g);
                }

            if(saveToFile)
                FileLoader.SaveGestures(RetrieveText());
        }
        public void RecordGesture(string gestureName, string ctxt)
        {
            if (_kinectHandler == null) return;

            _isRecognizing = false;
            _currentGesture = new Gesture(gestureName, ctxt);
            _kinectHandler.RecordingCountdownEvent(3);
            Thread.Sleep(1000);
            _kinectHandler.RecordingCountdownEvent(2);
            Thread.Sleep(1000);
            _kinectHandler.RecordingCountdownEvent(1);
            Thread.Sleep(1000);
            _kinectHandler.RecordingCountdownEvent(0);
            Thread.Sleep(1000);
            if (_seqCoords != null)
            {
                _seqCoords.Clear();
            }
            else
            {
                _seqCoords = new ArrayList();
            }
            _isRecording = true;
        }
        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());
            }
        }
示例#5
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());
            }
        }