Esempio 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);
        }