コード例 #1
0
        /// <summary>
        /// Recognize what gate a shape is using the ComboRecgonizer,
        /// and update the shape with the results.
        /// </summary>
        /// <param name="shape">
        /// The shape to recognize (should be a gate)
        /// </param>
        public override void recognize(Sketch.Shape shape, Featurefy.FeatureSketch featureSketch)
        {
            // Initialize variables to store results in
            ShapeType bestType        = new ShapeType();
            float     bestProbability = 0F;
            double    bestOrientation;

            // Recognize the shape and pick out the best option
            Dictionary <ShapeType, double> alternativeTypes = Recognize(shape, out bestOrientation);

            foreach (KeyValuePair <ShapeType, double> pair in alternativeTypes)
            {
                ShapeType type = pair.Key;
                double    prob = pair.Value;
                if (prob > bestProbability)
                {
                    bestType        = type;
                    bestProbability = (float)prob;
                }
            }

            // Update the shape to reflect this recognition
            shape.setRecognitionResults(
                bestType,
                bestProbability,
                alternativeTypes,
                bestOrientation);
        }
コード例 #2
0
        /// <summary>
        /// Uses the RecognitionInterfaces.Recognizer recognize method
        /// which recognizes and assigns the type of a shape.  This
        /// implementation allows the use of the learnFromExample
        /// method in Interface Functions.
        /// </summary>
        /// <param name="shape">The shape to recognize</param>
        /// <param name="featureSketch">The featureSketch to use</param>
        public override void recognize(Sketch.Shape shape, Featurefy.FeatureSketch featureSketch)
        {
            BitmapSymbol      unknown = new BitmapSymbol(shape.SubstrokesL);
            List <SymbolRank> results = unknown.Recognize(_templates);

            if (results.Count > 0)
            {
                // Populate the dictionary of alterateTypes with all of the ShapeTypes in results
                Dictionary <ShapeType, double> alternateTypes = new Dictionary <ShapeType, double>();

                if (debug)
                {
                    Console.WriteLine("\nRecognition results: ");
                }

                foreach (SymbolRank result in results)
                {
                    if (!alternateTypes.ContainsKey(result.SymbolType))
                    {
                        alternateTypes.Add(result.SymbolType, getProbability(result.SymbolType, results));
                    }

                    if (debug)
                    {
                        Console.WriteLine(result.SymbolType + " with template " + result.SymbolName);
                    }
                }

                ShapeType type = results[0].SymbolType;          // the most likely type

                float probability = (float)alternateTypes[type]; // grab the probability of our most likely type

                alternateTypes.Remove(type);                     // the most likely type is NOT an alternate

                shape.setRecognitionResults(
                    type,
                    probability,
                    alternateTypes,
                    results[0].BestOrientation,
                    results[0].SymbolName);
            }
        }