Esempio n. 1
0
        /// <summary>
        /// Compares a points of a single gesture, to the points in a single saved gesture, and returns a accuracy probability.
        /// </summary>
        /// <param name="compareTo">Learned PointPattern from PointPatternSet to compare gesture points to.</param>
        /// <param name="points">Points of the current gesture being analyzed.</param>
        /// <returns>Returns the accuracy probability of the learned PointPattern to the current gesture.</returns>
        public PointPatternMatchResult GetPointPatternMatchResult(PointPattern compareTo, Point[] points)
        {
            //compare points



            // Ensure we have at least 2 points or recognition will fail as we are unable to interpolate between a single point.
            if (points.Length < 2)
            {
                throw new ArgumentOutOfRangeException("hello" /*nameof(points)*/);
            }

            // We'll use an array of doubles that matches the number of interpolation points to hold
            // the dot products of each angle comparison.
            var dotProducts = new double[Precision];
            var myDistance  = new double[Precision];

            // We'll need to interpolate the incoming points array and the points of the learned gesture.
            // We do this for each comparison so that we can change the precision at any time and not lose
            // or original learned gesture to multiple interpolations.
            var interpolatedCompareTo  = PointPatternMath.GetInterpolatedPointArray(compareTo.Points, Precision);
            var interpolatedPointArray = PointPatternMath.GetInterpolatedPointArray(points, Precision);

            int   ij            = 0;
            float totalDistance = 0;

            foreach (Point p in interpolatedCompareTo)
            {
                Vector2 v1 = new Vector2((float)p.X, (float)p.Y);
                Vector2 v2 = new Vector2((float)interpolatedPointArray[ij].X, (float)interpolatedPointArray[ij].Y);
                float   d  = Vector2.Distance(v1, v2);
                myDistance[ij] = Vector2.Distance(v1, v2);
                totalDistance  = totalDistance + d;
                ij++;
            }

            // Debug.Log("distance is " + totalDistance);

            // Next we'll get an array of angles for each interpolated point in the learned and current gesture.
            // We'll get the same number of angles corresponding to the total number of interpolated points.
            var    anglesCompareTo = PointPatternMath.GetPointArrayAngles(interpolatedCompareTo);
            var    angles          = PointPatternMath.GetPointArrayAngles(interpolatedPointArray);
            double averageDistance = myDistance.Average();

            // Now that we have angles for each gesture, we'll get the dot product of every angle equal to
            // the total number of interpolation points.
            for (var i = 0; i <= anglesCompareTo.Length - 1; i++)
            {
                dotProducts[i] = PointPatternMath.GetDotProduct(anglesCompareTo[i], angles[i]);
            }

            // Convert average dot product to probability since we're using the deviation
            // of the average of the dot products of every interpolated point in a gesture.
            var probability = PointPatternMath.GetProbabilityFromDotProduct(dotProducts.Average());

            // Return PointPatternMatchResult object that holds the results of comparison.
            return(new PointPatternMatchResult(compareTo.Name, probability, 1, totalDistance, averageDistance));
        }
Esempio n. 2
0
        // Update is called once per frame
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                typing      = true;
                firstLetter = lastCollision;
                // Debug.Log("first is " + firstLetter);
            }// Debug.Log("Pressed left click.");
            if (Input.GetMouseButtonDown(1))
            {
                typing = false;                             // Debug.Log("Pressed right click.");
            }
            xpos = Input.GetAxis("Mouse X");
            ypos = Input.GetAxis("Mouse Y");

            displac.x = xpos;
            displac.y = ypos;
            displac.z = 0f;

            displac.x = xpos * 0.3F;
            displac.y = ypos * 0.3F;
            displac.z = 0f;

            Vector3 position = this.transform.position;

            if (this.transform.position.x + displac.x < minX)      //-5.5)
            {
                position.x = minX;                                 //-5.5f;
            }
            else if (this.transform.position.x + displac.x > maxX) // 5.5)
            {
                position.x = maxX;                                 //5.5f;
            }
            else
            {
                position.x += displac.x;
            }

            if (this.transform.position.y + displac.y < minY)//-2.4)
            {
                position.y = minY;
            }
            else if (this.transform.position.y + displac.y > maxX)//2.4)
            {
                position.y = maxX;
            }
            else
            {
                position.y += displac.y;
            }

            //  position.y += displac.y;
            position.z += displac.z;



            try
            {
                this.transform.position = position;
                // this.transform.Translate(displac);
            }
            catch (System.Exception)
            {
            }


            if (typing)
            {
                this.GetComponent <Renderer>().material.SetColor("_Color", Color.green);
                this.GetComponent <TrailRenderer>().widthMultiplier = 0.1f;
                this.GetComponent <TrailRenderer>().time            = 6f;
                xpos = Input.GetAxis("Mouse X");
                ypos = Input.GetAxis("Mouse Y");

                displac.x = xpos;
                displac.y = ypos;
                displac.z = 0f;

                displac.x = xpos * 0.3F;
                displac.y = ypos * 0.3F;
                displac.z = 0f;

                position = this.transform.position;

                if (this.transform.position.x + displac.x < minX)      //-5.5)
                {
                    position.x = minX;                                 //-5.5f;
                }
                else if (this.transform.position.x + displac.x > maxX) // 5.5)
                {
                    position.x = maxX;                                 //5.5f;
                }
                else
                {
                    position.x += displac.x;
                }

                if (this.transform.position.y + displac.y < minY)//-2.4)
                {
                    position.y = minY;
                }
                else if (this.transform.position.y + displac.y > maxX)//2.4)
                {
                    position.y = maxX;
                }
                else
                {
                    position.y += displac.y;
                }

                //  position.y += displac.y;
                position.z += displac.z;



                try
                {
                    this.transform.position = position;
                    // this.transform.Translate(displac);
                }
                catch (System.Exception)
                {
                }

                p.X = this.transform.position.x;  //xpos;// mycursor.transform.position.x;
                p.Y = this.transform.position.y;; //ypos;// mycursor.transform.position.y;

                myPattren.Add(p);

                // drawingPattern[i] = p;

                i = i + 1;
            }


            if (!typing && myPattren.Count > 0)
            {
                this.GetComponent <Renderer>().material.SetColor("_Color", Color.red);

                Point[] mypointsN = new Point[myPattren.Count];

                mypointsN = myPattren.ToArray();

                var interPolatedArray = PointPatternMath.GetInterpolatedPointArray(mypointsN, 20);


                myPattren.Clear();

                //   compare with all patterns

                RecognizeGesture(mypointsN);

                Debug.Log(myTopResults);
            }

            /* when user finishes entering a word*/
            //if (!typing && myPattren.Count > 0)
            //{
            //    Debug.Log("list debug");
            //    foreach (Point p in myPattren)
            //    {

            //        Debug.Log(p.X + " " + p.Y);
            //    }


            //    //interpolate and print

            //    //change list to array

            //    Point[] mypointsN = new Point[myPattren.Count];

            //    mypointsN = myPattren.ToArray();

            //    var interPolatedArray = PointPatternMath.GetInterpolatedPointArray(mypointsN, 20);
            //    Debug.Log(interPolatedArray.Length);

            //    Debug.Log(interPolatedArray[2].X);

            //    for (int t = 0; t < interPolatedArray.Length; t++)
            //    {
            //        Debug.Log("interpolated array");
            //        Debug.Log(interPolatedArray[t].X + " " + interPolatedArray[t].Y);

            //    }


            //    //empty list

            //    myPattren.Clear();

            //    //compare with all patterns

            //    RecognizeGesture(mypointsN);

            //    //list of patterns

            //    //mypt.

            //    // myPointAnalyzer.GetPointPatternMatchResult(interPolatedArray,interPolatedArray);


            //    //add word with highest probability to the text input area, and show all 3 options closest

            //    //showpresentedText();

            //    string wo = myTopResults[0].Name + ' ' + myTopResults[0].Probability.ToString();
            //    ttSoFar = ttext.GetComponent<Text>().text;
            //    ttext.GetComponent<Text>().text = ttSoFar + " " + wo;// " " + " transcribed text";// wordResult[1];

            //    option1.GetComponent<Text>().text = myTopResults[0].Name;
            //    option2.GetComponent<Text>().text = myTopResults[1].Name;
            //    option3.GetComponent<Text>().text = myTopResults[2].Name;



            //    //int j = 0;
            //    //Debug.Log("kutough");
            //    //Debug.Log(drawingPattern.Length.ToString()+" nanzo");

            //    //while (j<drawingPattern.Length) {
            //    //   Debug.Log(drawingPattern[i].X.ToString() + " " + drawingPattern[i].Y.ToString());
            //    //    j++;
            //    //}
            //}
        }
Esempio n. 3
0
        // Update is called once per frame
        void Update()
        {
            //check if key is over the enter button



            //Debug.Log(force);
            //if (!typing)
            //{
            //    i = 0;


            //    if (!startTyping)
            //    {
            //        //calculateMetrics();
            //        //ttext.GetComponent<Text>().text = ""; //clear text area and show presented text
            //        //    ptext.GetComponent<Text>().text = "presented text";
            //        //}
            //        showTextToTranscribe();
            //    }

            //}

            /*when user finishes typing a phrase*/

            //if (entered)
            //{
            //    //calculate metrics
            //    calculateMetrics();
            //    writeLog();
            //    //clear textboxes and show show phrase
            //    showTextToTranscribe();

            //}

            /* when user finishes entering a word*/
            if (!typing && myPattren.Count > 0)
            {
                Debug.Log("list debug");
                foreach (Point p in myPattren)
                {
                    Debug.Log(p.X + " " + p.Y);
                }


                //interpolate and print

                //change list to array

                Point[] mypointsN = new Point[myPattren.Count];

                mypointsN = myPattren.ToArray();

                var interPolatedArray = PointPatternMath.GetInterpolatedPointArray(mypointsN, 20);
                Debug.Log(interPolatedArray.Length);

                Debug.Log(interPolatedArray[2].X);

                for (int t = 0; t < interPolatedArray.Length; t++)
                {
                    Debug.Log("interpolated array");
                    Debug.Log(interPolatedArray[t].X + " " + interPolatedArray[t].Y);
                }


                //empty list

                myPattren.Clear();

                //compare with all patterns

                RecognizeGesture(mypointsN);

                //list of patterns

                //mypt.

                // myPointAnalyzer.GetPointPatternMatchResult(interPolatedArray,interPolatedArray);


                //add word with highest probability to the text input area, and show all 3 options closest

                //showpresentedText();

                string wo = myTopResults[0].Name + ' ' + myTopResults[0].Probability.ToString();
                ttSoFar = ttext.GetComponent <Text>().text;
                ttext.GetComponent <Text>().text = ttSoFar + " " + wo;// " " + " transcribed text";// wordResult[1];

                option1.GetComponent <Text>().text = myTopResults[0].Name;
                option2.GetComponent <Text>().text = myTopResults[1].Name;
                option3.GetComponent <Text>().text = myTopResults[2].Name;



                //int j = 0;
                //Debug.Log("kutough");
                //Debug.Log(drawingPattern.Length.ToString()+" nanzo");

                //while (j<drawingPattern.Length) {
                //   Debug.Log(drawingPattern[i].X.ToString() + " " + drawingPattern[i].Y.ToString());
                //    j++;
                //}
            }


            string cmd = CheckForRecievedData();


            try
            {
                // print(stream.ReadLine());

                if (cmd.StartsWith("F"))     //Got a force
                {
                    //print("hey");
                    force = ParseFSRData(cmd);
                    print(force);

                    if (force > 10 && force < 500)  //position soft touch
                    {
                        positioning = true;
                        typing      = false;
                    }

                    else if (force > 500)   //typing
                    {
                        typing      = true;
                        positioning = false;

                        //while start
                        //while (typing)
                        //{

                        //p.X = mycursor.transform.position.x;
                        //p.Y = mycursor.transform.position.y;


                        //  }//end while
                    }

                    else
                    {
                        typing = false; positioning = false;
                    }
                }

                //   else { force = 0; typing = false; positioning = false; }
            }
            catch (System.Exception)
            {
            }


            /*typing*/

            if (typing)
            {
                this.GetComponent <Renderer>().material.SetColor("_Color", Color.green);
                this.GetComponent <TrailRenderer>().widthMultiplier = 0.1f;
                this.GetComponent <TrailRenderer>().time            = 6f;
                xpos = Input.GetAxis("Mouse X");
                ypos = Input.GetAxis("Mouse Y");

                displac.x = xpos;
                displac.y = ypos;
                displac.z = 0f;

                displac.x = xpos * 0.3F;
                displac.y = ypos * 0.3F;
                displac.z = 0f;



                Vector3 position = this.transform.position;

                if (this.transform.position.x + displac.x < minX)      //-5.5)
                {
                    position.x = minX;                                 //-5.5f;
                }
                else if (this.transform.position.x + displac.x > maxX) // 5.5)
                {
                    position.x = maxX;                                 //5.5f;
                }
                else
                {
                    position.x += displac.x;
                }

                if (this.transform.position.y + displac.y < minY)//-2.4)
                {
                    position.y = minY;
                }
                else if (this.transform.position.y + displac.y > maxX)//2.4)
                {
                    position.y = maxX;
                }
                else
                {
                    position.y += displac.y;
                }

                //  position.y += displac.y;
                position.z += displac.z;
                //  myTransform.position = position;


                //   displac.x = Mathf.Clamp(displac.x, minX, maxX);
                //  displac.y = Mathf.Clamp(displac.y, minY, maxY);


                try
                {
                    this.transform.position = position;
                    // this.transform.Translate(displac);
                }
                catch (System.Exception)
                {
                }

                p.X = this.transform.position.x;  //xpos;// mycursor.transform.position.x;
                p.Y = this.transform.position.y;; //ypos;// mycursor.transform.position.y;

                myPattren.Add(p);

                // drawingPattern[i] = p;

                i = i + 1;
                // Debug.Log(i);
            }

            /*position cursor*/

            if (positioning)
            {
                this.GetComponent <Renderer>().material.SetColor("_Color", Color.red);
                this.GetComponent <TrailRenderer>().widthMultiplier = 0.0f;
                this.GetComponent <TrailRenderer>().time            = 0.01f;

                xpos = Input.GetAxis("Mouse X");
                ypos = Input.GetAxis("Mouse Y");

                displac.x = xpos * 0.3F;
                displac.y = ypos * 0.3F;
                displac.z = 0f;



                Vector3 position = this.transform.position;

                //if (this.transform.position.x + displac.x < -5.5)
                //    position.x = -5.5f;
                //else if (this.transform.position.x + displac.x > 5.5)
                //    position.x = 5.5f;
                //else
                //    position.x += displac.x;

                //if (this.transform.position.y + displac.y < -2.4)
                //    position.y = -2.4f;
                //else if (this.transform.position.y + displac.y > 2.4)
                //    position.y = 2.4f;
                //else
                //    position.y += displac.y;

                if (this.transform.position.x + displac.x < minX)      //-5.5)
                {
                    position.x = minX;                                 //-5.5f;
                }
                else if (this.transform.position.x + displac.x > maxX) // 5.5)
                {
                    position.x = maxX;                                 //5.5f;
                }
                else
                {
                    position.x += displac.x;
                }

                if (this.transform.position.y + displac.y < minY)//-2.4)
                {
                    position.y = minY;
                }
                else if (this.transform.position.y + displac.y > maxX)//2.4)
                {
                    position.y = maxX;
                }
                else
                {
                    position.y += displac.y;
                }

                //  position.y += displac.y;
                position.z += displac.z;
                //  myTransform.position = position;


                //   displac.x = Mathf.Clamp(displac.x, minX, maxX);
                //  displac.y = Mathf.Clamp(displac.y, minY, maxY);


                try
                {
                    this.transform.position = position;
                    // this.transform.Translate(displac);
                }
                catch (System.Exception)
                {
                }
            }

            if (!positioning && !typing)
            {
                this.GetComponent <Renderer>().material.SetColor("_Color", Color.red);
                this.GetComponent <TrailRenderer>().widthMultiplier = 0.0f;
            }
        }