示例#1
0
        public static string[] LoadGestures(DtwGestureRecognizer dtw)
        {
            if(dtw == null )
            {
                Log.Error("DtwGestureRecognizer is null");
                return null;
            }

            Log.Debug("Loading gestures");
            string[] result = null;
            var itemCount = 0;
            string line;
            var gestureName = "";
            var contextName = "";
            var frames = new ArrayList();
            var items = new double[12];

            // Read the file and display it line by line.
            if (!File.Exists(DefaultPath + "gestures.sav"))
            {
                Log.Error("Gesture file not found");
                return null;
            }

            var file = new StreamReader(DefaultPath + "gestures.sav");

            var counter = 0;

            while ((line = file.ReadLine()) != null)
            {
                if (line.StartsWith("//"))
                {
                    var numGestures = Int32.Parse(line.Split('=')[1]);
                    if (numGestures != 0)
                    {
                        result = new string[numGestures];
                    }
                    else
                    {
                        return null;
                    }
                    continue;
                }
                if (line.StartsWith("@"))
                {
                    gestureName = line.Substring(1);
                    if (result != null) result[counter] = gestureName;
                    continue;
                }

                if (line.StartsWith("$"))
                {
                    contextName = line.Substring(1);
                    if (result != null) result[counter] += ";" + contextName;
                    continue;
                }

                if (line.StartsWith("~"))
                {
                    frames.Add(items);
                    itemCount = 0;
                    items = new double[12];
                    continue;
                }

                if (!line.StartsWith("----"))
                {
                    items[itemCount] = Double.Parse(line);
                }

                itemCount++;

                if (line.StartsWith("----"))
                {
                    if (frames.Count == 0) continue;
                    Log.Debug("Gesture frames loaded. Saving...");
                    dtw.AddOrUpdate(frames, gestureName, contextName, false);
                    frames = new ArrayList();
                    gestureName = String.Empty;
                    contextName = String.Empty;
                    counter++;
                    itemCount = 0;
                }
            }

            Log.Debug(counter + " Gestures loaded");
            file.Close();
            return result;
        }
示例#2
0
        public static string[] LoadGestures(DtwGestureRecognizer dtw)
        {
            if (dtw == null)
            {
                Log.Error("DtwGestureRecognizer is null");
                return(null);
            }

            Log.Debug("Loading gestures");
            string[] result    = null;
            var      itemCount = 0;
            string   line;
            var      gestureName = "";
            var      contextName = "";
            var      frames      = new ArrayList();
            var      items       = new double[12];

            // Read the file and display it line by line.
            if (!File.Exists(DefaultPath + "gestures.sav"))
            {
                Log.Error("Gesture file not found");
                return(null);
            }

            var file = new StreamReader(DefaultPath + "gestures.sav");

            var counter = 0;

            while ((line = file.ReadLine()) != null)
            {
                if (line.StartsWith("//"))
                {
                    var numGestures = Int32.Parse(line.Split('=')[1]);
                    if (numGestures != 0)
                    {
                        result = new string[numGestures];
                    }
                    else
                    {
                        return(null);
                    }
                    continue;
                }
                if (line.StartsWith("@"))
                {
                    gestureName = line.Substring(1);
                    if (result != null)
                    {
                        result[counter] = gestureName;
                    }
                    continue;
                }

                if (line.StartsWith("$"))
                {
                    contextName = line.Substring(1);
                    if (result != null)
                    {
                        result[counter] += ";" + contextName;
                    }
                    continue;
                }

                if (line.StartsWith("~"))
                {
                    frames.Add(items);
                    itemCount = 0;
                    items     = new double[12];
                    continue;
                }

                if (!line.StartsWith("----"))
                {
                    items[itemCount] = Double.Parse(line);
                }

                itemCount++;

                if (line.StartsWith("----"))
                {
                    if (frames.Count == 0)
                    {
                        continue;
                    }
                    Log.Debug("Gesture frames loaded. Saving...");
                    dtw.AddOrUpdate(frames, gestureName, contextName, false);
                    frames      = new ArrayList();
                    gestureName = String.Empty;
                    contextName = String.Empty;
                    counter++;
                    itemCount = 0;
                }
            }

            Log.Debug(counter + " Gestures loaded");
            file.Close();
            return(result);
        }
示例#3
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());
            }
        }