Example #1
0
        /// <summary>
        /// Find the deviation distance when rotated to fix to all 8 segments (45 deg * 8 segments = 360deg) gets the smallest deviation distance amongst them
        /// </summary>
        /// <param name="points">Input stroke</param>
        /// <param name="T">Unistroke model</param>
        /// <param name="a">min AngleRange</param>
        /// <param name="b">max AngleRange</param>
        /// <param name="threshold">Angle Precision</param>
        /// <returns>Smallest possible deviation distance</returns>
        public static float DistanceAtBestAngle(Point[] points, Unistroke T, float a, float b, float threshold)
        {
            float x1 = Phi * a + (1f - Phi) * b;
            float f1 = DistanceAtAngle(points, T, x1);
            float x2 = (1f - Phi) * a + Phi * b;
            var   f2 = DistanceAtAngle(points, T, x2);

            while (Mathf.Abs(b - a) > threshold)
            {
                if (f1 < f2)
                {
                    b  = x2;
                    x2 = x1;
                    f2 = f1;
                    x1 = Phi * a + (1f - Phi) * b;
                    f1 = DistanceAtAngle(points, T, x1);
                }
                else
                {
                    a  = x1;
                    x1 = x2;
                    f1 = f2;
                    x2 = (1f - Phi) * a + Phi * b;
                    f2 = DistanceAtAngle(points, T, x2);
                }
            }
            return(Mathf.Min(f1, f2));
        }
Example #2
0
        public Result Recognize(Point[] points, Model.StrokeTypeTest test)
        {
            Result result;

            int t0 = System.DateTime.Now.Millisecond;

            Unistroke input = new Unistroke(points, EvaluationType.ProportionateProtractor);

            float b = float.PositiveInfinity;
            int   u = -1;

            List <Unistroke> unistrokes = model.GetDataSet(test);

            for (int i = 0; i < unistrokes.Count; i++)
            {
                Unistroke evaluatedModel = new Unistroke(unistrokes[i]._unistroke, EvaluationType.ProportionateProtractor);
                float     d;
                d = Util.OptimalCosineDistance(evaluatedModel.Vector, input.Vector);

                if (d < b)
                {
                    b = d;
                    u = i;
                }
            }

            int elapsedTime = System.DateTime.Now.Millisecond - t0;

            Debug.Log("recognizing");
            if (u == -1)
            {
                result = new Result("no match", "-", "-", 0f, elapsedTime, new Unistroke("no match", "", "", new Point[] { }, EvaluationType.None));
                Debug.Log("result: " + result);
            }
            else
            {
                float score = 1f / b;
                result = new Result(unistrokes[u].Name, unistrokes[u].Variant, unistrokes[u].Test, score, elapsedTime, unistrokes[u]);
            }
            return(result);
        }
Example #3
0
        public void AddGesture(Point[] points, string testCat, EvaluationType evaluationType)
        {
            string msg = "point list to add: ";

            for (int i = 0; i < points.Length; i++)
            {
                msg += "[" + points[i].X + "," + points[i].Y + "] ";
            }
            Debug.Log(msg);

            Unistroke gesture = new Unistroke(model.strokeClassification.name, model.strokeClassification.variant, testCat, points, evaluationType);

            if (testCat == StrokeType.test_positive)
            {
                model.positiveList.Add(gesture);
                model.SaveDataSet(StrokeType.test_positive);
            }
            else if (testCat == StrokeType.test_negative)
            {
                model.negativeList.Add(gesture);
                model.SaveDataSet(StrokeType.test_negative);
            }
        }
Example #4
0
 /// <summary>
 /// Finds deviation distance after adjusting rotation
 /// </summary>
 /// <param name="points">Input stroke</param>
 /// <param name="T">Unistroke model</param>
 /// <param name="radians">Rotation transform</param>
 /// <returns>Deviation distance</returns>
 public static float DistanceAtAngle(Point[] points, Unistroke T, float radians)
 {
     Point[] newpoints = RotateBy(points, radians);
     return(PathDistance(newpoints, T.Points));
 }
Example #5
0
 private void DrawGestureFromPoints(Dollar.One.Point[] points)
 {
     Dollar.One.Unistroke unistroke = new Dollar.One.Unistroke(points, Dollar.One.EvaluationType.ProportionateProtractor);
     DrawStrokeFromPoints(unistroke.Points);
 }