Exemplo n.º 1
0
        /// <summary>
        /// Compute the probability that a given set of substrokes has the given type.
        /// </summary>
        /// <param name="substrokes"></param>
        /// <param name="type"></param>
        /// <param name="featureSketch"></param>
        /// <returns>a pair containing the recognition probability and the orientation</returns>
        private RecognitionResult computeRecognitionProbabilityForTextOrWire(SubstrokeCollection substrokes, ShapeType type, FeatureSketch featureSketch)
        {
            double probability = 0;
            double orientation = 0;

            PhantomShape shape = new PhantomShape();

            shape.AddSubstrokes(substrokes);

            if (LogicDomain.IsWire(type))
            {
                // the probability it is a wire is defined as
                // (# substrokes classified as wires) / (total # substrokes)

                int numSubstrokes     = substrokes.Count;
                int numWireSubstrokes = 0;

                foreach (Substroke substroke in substrokes)
                {
                    if (_classifications[substroke] == LogicDomain.WIRE_CLASS)
                    {
                        numWireSubstrokes++;
                    }
                }

                probability = (double)numWireSubstrokes / numSubstrokes;
                return(new RecognitionResult(LogicDomain.WIRE, probability, orientation));
            }
            else if (LogicDomain.IsText(type))
            {
                // the probability it is text is defined as
                // (# substrokes classified as text) / (total # substrokes)

                int numSubstrokes     = substrokes.Count;
                int numTextSubstrokes = 0;

                foreach (Substroke substroke in substrokes)
                {
                    if (_classifications[substroke] == LogicDomain.TEXT_CLASS)
                    {
                        numTextSubstrokes++;
                    }
                }

                probability = (double)numTextSubstrokes / numSubstrokes;
                return(new TextRecognitionResult(probability, _textRecognizer.read(shape)));
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// For each type, get an estimate of the probability that the given shape is of the given type
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="shape"></param>
        /// <param name="types"></param>
        /// <param name="featureSketch"></param>
        /// <returns></returns>
        private Dictionary <ShapeType, RecognitionResult> computeRecognitionProbabilities(
            SubstrokeCollection substrokes,
            FeatureSketch featureSketch)
        {
            PhantomShape shape = new PhantomShape();

            shape.AddSubstrokes(substrokes);

            Dictionary <ShapeType, RecognitionResult> results = Data.Utils.replaceValues(
                _gateRecognizer.RecognitionResults(shape, LogicDomain.Gates),
                r => { return((RecognitionResult)r); });

            foreach (ShapeType type in LogicDomain.Types)
            {
                if (!results.ContainsKey(type))
                {
                    results.Add(type, computeRecognitionProbabilityForTextOrWire(substrokes, type, featureSketch));
                }
            }

            return(results);
        }