Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frame"/> class.
        /// </summary>
        /// <param name="sampleSet">The matrix of touch-sensory data values.</param>
        /// <param name="timestamp">The time stamp.</param>
        public Frame(double[,] sampleSet, DateTime timestamp)
        {
            TimeStamp = timestamp;
            if (sampleSet != null)
            {
                var clusterer = new GestureRecognition.Clusterer(sampleSet.Length);
                var cluster   = clusterer.Cluster(sampleSet, 4);

                foreach (var c in cluster.Values)
                {
                    //get blob extension in x and y axis
                    double cX = 1, cY = 1;
                    int    count = 0;
                    double val   = 0;
                    foreach (var m in c.ClusterSet.Values)
                    {
                        int x = m / sampleSet.GetLength(1);
                        int y = m % sampleSet.GetLength(1);
                        try
                        {
                            val += sampleSet[x, y];
                            count++;
                        }
                        catch { }
                        if (Math.Abs(x - c.Mean[0]) >= cX)
                        {
                            cX = Math.Abs(x - c.Mean[0]);
                        }
                        if (Math.Abs(y - c.Mean[1]) >= cY)
                        {
                            cY = Math.Abs(y - c.Mean[1]);
                        }
                    }
                    Touch t = new Touch(c.Id, c.Mean[0], c.Mean[1], cX, cY, val / count);
                    AddTouch(t);
                }
            }
        }
        private Frame GetFrameFromSampleSet(double[,] sampleSet)
        {
            List<Touch> touchList = new List<Touch>();
            if (sampleSet != null)
            {
                var clusterer = new GestureRecognition.Clusterer(sampleSet.Length);
                var cluster = clusterer.Cluster(sampleSet, 0);

                foreach (var c in cluster.Values)
                {
                    //get blob extension in x and y axis
                    double cX = 1, cY = 1;
                    int count = 0;
                    double val = 0;
                    foreach (var m in c.ClusterSet.Values)
                    {
                        int x = m / sampleSet.GetLength(1);
                        int y = m % sampleSet.GetLength(1);
                        try
                        {
                            val += sampleSet[x, y];
                            count++;
                        }
                        catch { }
                        if (Math.Abs(x - c.Mean[0]) >= cX) cX = Math.Abs(x - c.Mean[0]);
                        if (Math.Abs(y - c.Mean[1]) >= cY) cY = Math.Abs(y - c.Mean[1]);
                    }
                    Touch t = new Touch(c.Id, c.Mean[0], c.Mean[1], cX, cY, val / count);
                    touchList.Add(t);
                }
            }
            Frame frame = new Frame(DateTime.Now, touchList.ToArray());
            return frame;
        }