Beispiel #1
0
        /// <summary>
        /// This function is called to get normalised result before passing to DTW algorithm.
        /// The input from the Kinect and the text files are normalised and passed into DTW.
        /// If the gesture name matches with the input, the name of gesture is received in the parameter finalgesture.
        /// </summary>
        ///  <param name="gesturename">It is used to describe the name of gesture in dataset with which the Body coordinates are going to be compared with</param>
        /// <returns>returns the gesture matched from DTW</returns>
        private string passToDTW(string gesturename)
        {
            try
            {
                Recorder        recorder          = new Recorder();
                ArrayList       gesturefromkinect = recorder.readFiles(KINECT_COORDINATES);// getting normalised co ordinates here.....
                string          storedtextLines   = System.IO.File.ReadAllText(gesturename);
                List <double[]> normalisedresult  = new List <double[]>();

                string[] result = storedtextLines.Split('@');
                for (int i = 0; i < result.Length; i++)
                {
                    normalisedresult = recorder.explode_array(result, ',');
                }
                string txtFiles = Path.GetFileName(gesturename);

                int dimension      = 12;
                int threshold      = 3;
                int firstThreshold = 5;
                int maxSlope       = 2;
                int minimumLength  = 10;
                _dtw = new DTW(dimension, threshold, firstThreshold, maxSlope, minimumLength);
                ArrayList       arrlstTemp = ArrayList.Adapter(normalisedresult);
                Regex           regex      = new Regex(@"_(.+?)_");
                MatchCollection mc2        = regex.Matches(txtFiles);
                _dtw.Add(arrlstTemp, "The gesture is " + mc2[0]);
                finalgesture       = _dtw.recognize(gesturefromkinect);
                KINECT_COORDINATES = new string[] { };
            }
            catch (Exception ex)
            { }
            return(finalgesture);
        }
Beispiel #2
0
        /// <summary>
        /// This function is called to get normalised result before passing to DTW algorithm.
        /// The input from the Kinect and the text files are normalised and passed into DTW.
        /// If the gesture name matches with the input, the name of gesture is received in the parameter finalgesture.
        /// </summary>
        /// <returns>returns the gesture matched from DTW with least cost</returns>
        private string passToDTW()
        {
            string finalgesture = String.Empty;

            try
            {   //initialization of Dictionary where key=gesture and value is the cost from DTW
                var       mySortedDictionary = new SortedDictionary <string, double>();
                Recorder  rd = new Recorder();
                ArrayList gesturefromkinect = rd.readfiles(KINECT_COORDINATES);// getting normalised co ordinates here.....
                string    sourceDirectory   = @"d:\DTW_files\2D\Hristo";
                var       txtFiles          = Directory.EnumerateFiles(sourceDirectory, "*.txt");
                foreach (string currentFile in txtFiles)
                {
                    System.Diagnostics.Debug.WriteLine("\nComparing with " + currentFile);
                    string          storedtextLines  = System.IO.File.ReadAllText(currentFile);
                    List <double[]> normalisedresult = new List <double[]>();

                    string[] result = storedtextLines.Split('@');
                    for (int i = 0; i < result.Length; i++)
                    {
                        normalisedresult = rd.explode_array(result, ',');
                    }
                    int dimension      = 12;
                    int threshold      = 2;
                    int firstThreshold = 4;
                    int maxSlope       = 2;
                    int minimumLength  = 10;
                    _dtw = new DTW(dimension, threshold, firstThreshold, maxSlope, minimumLength);
                    ArrayList arrlstTemp = ArrayList.Adapter(normalisedresult);
                    _dtw.Add(arrlstTemp, Path.GetFileNameWithoutExtension(currentFile));
                    finalgesture = _dtw.recognize(gesturefromkinect);
                    if ((!finalgesture.Contains("__UNKNOWN")))
                    {
                        string[] words = finalgesture.Split('@');
                        double   Num;
                        bool     isNum = double.TryParse(words[1], out Num);
                        if (isNum)
                        {
                            mySortedDictionary.Add(words[0], Num);
                        }
                    }
                    KINECT_COORDINATES = new string[] { };
                }
                //find the gesture with the least cost from the set of the gestures
                if (mySortedDictionary.Count >= 1)
                {
                    double[]     indexableValues = mySortedDictionary.Values.ToArray();
                    double       min             = indexableValues.Min();
                    string       key             = (from d in mySortedDictionary where d.Value == min select d).First().Key;
                    GestureStore ig = new GestureStore("Recoginised as:" + key);
                }
            }
            catch (Exception ex)
            {
            }

            return(finalgesture);
        }