Пример #1
0
        public void load(string jsonName)
        {
            using (StreamReader r = new StreamReader(jsonName))
            {
                var     jsonString = r.ReadToEnd();
                JObject json       = (JObject)JsonConvert.DeserializeObject(jsonString);

                loadGestures = new List <CustomGesture>();

                foreach (KeyValuePair <string, JToken> kp in json)
                {
                    CustomGesture toAdd = new CustomGesture(kp.Key);

                    foreach (JToken gesture in (JArray)json[kp.Key])
                    {
                        foreach (KeyValuePair <string, JToken> pair in ((JObject)gesture))
                        {
                            toAdd.addDiscreteGesture(pair.Key, (float)pair.Value);
                        }
                    }

                    loadGestures.Add(toAdd);
                }
            }
        }
Пример #2
0
        private bool matchComplete(CustomGesture gestureToMatch, int index)
        {
            //Console.WriteLine("MATCH!! " + gestureToMatch.GestureName + " index " + index);
            if (firstFrame && index == 0) //tambem é primeiro frame
            {
                Console.WriteLine("fisrtMatch " + index + " " + gestureToMatch.GestureName);
                state.Add(new KeyValuePair <int, CustomGesture>(index, gestureToMatch));
            }
            else
            {                                                                   // deteção vai depender do estado anterior
                var newState = new HashSet <KeyValuePair <int, CustomGesture> >();
                foreach (var gest in state)                                     //loop pelos possiveis gestos
                {
                    if (gest.Value == gestureToMatch && index == gest.Key + 1)  //this guesture is the next
                    {
                        if (index == gestureToMatch.DiscreteGestures.Count - 1) //last gesture so FIND MATCH!!!
                        {
                            Console.WriteLine("Complete match " + index + " " + gestureToMatch.GestureName);
                            resetState();
                            return(true);
                        }
                        else
                        {
                            Console.WriteLine("Continue match " + index + " " + gestureToMatch.GestureName);
                            newState.Add(new KeyValuePair <int, CustomGesture>(index, gestureToMatch));
                        }
                    }
                }
                if (newState.Count > 0) //transição de estado se a continuação do gesto for valida
                {
                    state = newState;
                }
            }

            return(false);
        }