public void RecalculatePointNumber()
    {
        string    symbolName = dropDownList.options[dropDownList.value].text;
        MhGesture gest       = MhGestureManager.FindGesture(symbolName);

        var interpolatedPointArray = MhPointPatternMath.GetInterpolatedPointArray(gest.points, (int)recalculatePointNumber.value, gest);

        gest.points = new List <Vector2>(interpolatedPointArray);
        ClearSymbol();
        DrawSymbol();
    }
Example #2
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 MhPointPatternMatchResult GetPointPatternMatchResult(MhGesture compareTo, List <Vector2> points, int interpolationPoints)
    {
        // Ensure we have at least 2 points or recognition will fail as we are unable to interpolate between a single point.
        if (points.Count < 2 && interpolationPoints < 2)
        {
            throw new ArgumentOutOfRangeException("To few points or small inperpolation 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 List <float>(interpolationPoints + 1);

        // 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  = MhPointPatternMath.GetInterpolatedPointArray(compareTo.Points, interpolationPoints, compareTo);
        var interpolatedPointArray = MhPointPatternMath.GetInterpolatedPointArray(points, interpolationPoints, null);

        // 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 = MhPointPatternMath.GetPointArrayAngles(interpolatedCompareTo);
        var angles          = MhPointPatternMath.GetPointArrayAngles(interpolatedPointArray);

        // 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.Add(MhPointPatternMath.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 = MhPointPatternMath.GetProbabilityFromDotProduct(dotProducts.Average());

        //first 5th percent and last 5th percent is more important
        for (var i = 0; i <= (anglesCompareTo.Length / 20.0) - 1; i++)
        {
            dotProducts.Add(MhPointPatternMath.GetDotProduct(anglesCompareTo[i], angles[i]));
        }
        //last 5th percent
        for (int i = (int)((anglesCompareTo.Length / 100.0) * 95.0 - 1); i <= anglesCompareTo.Length - 1; i++)
        {
            dotProducts.Add(MhPointPatternMath.GetDotProduct(anglesCompareTo[i], angles[i]));
        }

        var probabilityAlt = MhPointPatternMath.GetProbabilityFromDotProduct(dotProducts.Average());

        // Return PointPatternMatchResult object that holds the results of comparison.
        return(new MhPointPatternMatchResult(compareTo.Name, probability, 1));
    }