Esempio n. 1
0
        public override DistanceResult Recognize(Gesture gesture, out List <string> errors)
        {
            errors = new List <string>();
            Dictionary <string, DistanceResult> results = new Dictionary <string, DistanceResult>();

            foreach (string key in Gesture.parameterKeys)
            {
                UnivariateAlgorithm[] univariateAlgorithms = parametersToAlgorithms[key];
                ParameterValues       parameterValues      = gesture[key];
                double[][]            normalizedValues     = parameterValues.GetNormalizedValues();
                normalizedValues = normalizedValues.Transpose();
                DistanceResult resultsParameter = null;
                for (int i = 0; i < parameterValues.Dimension; i++)
                {
                    List <string>  parameterErrors;
                    DistanceResult tempResult = univariateAlgorithms[i].Recognize(normalizedValues[i], out parameterErrors);
                    errors.Append(parameterErrors);
                    if (resultsParameter == null)
                    {
                        resultsParameter = tempResult;
                    }
                    else
                    {
                        resultsParameter = resultsParameter.Intersect(tempResult);
                    }
                }

                results.Add(key, resultsParameter);
            }
            DistanceResult possibleResults   = null;
            List <int>     impossibleResults = new List <int>();

            foreach (string key in Gesture.parameterKeys)
            {
                if (possibleResults == null)
                {
                    possibleResults = results[key];
                }
                else
                {
                    List <int> keys = possibleResults.Keys.ToList();
                    foreach (int result in keys)
                    {
                        if (!results[key].ContainsKey(result))
                        {
                            impossibleResults.Add(result);
                        }
                        else
                        {
                            possibleResults[result] = possibleResults[result] + results[key][result];
                        }
                    }
                }
            }
            foreach (int classIndex in impossibleResults)
            {
                possibleResults.Remove(classIndex);
            }
            if (possibleResults.Count == 0)
            {
                possibleResults.Add(-1, 0);
            }
            return(possibleResults);
        }