예제 #1
0
        /// <summary>
        /// Recognizes the text a shape forms, and updates the
        /// shape with the recognition results (the text and the
        /// likelihood that the recognition was correct).
        ///
        /// This method does not use the featureSketch argument.
        ///
        /// Postcondition: the shape is of type IO and its Name
        /// property tells what text it was recognized as.
        /// </summary>
        /// <param name="shape">The shape to recognize</param>
        /// <param name="featureSketch">Not used.</param>
        public override void recognize(Sketch.Shape shape, Featurefy.FeatureSketch featureSketch)
        {
            // Prepare the shape for recognition
            SketchOrInkConverter converter = new SketchOrInkConverter();

            _microsoftTextRecognizer.Strokes = converter.convertToInk(shape);

            // Try to recognize the shape
            RecognitionStatus status;
            RecognitionResult result;

            result = _microsoftTextRecognizer.Recognize(out status);

            // Origanize the results
            string shapeName   = "";
            float  probability = 0F;

            if ((result != null) && (status == RecognitionStatus.NoError))
            {
                shapeName = result.TopString;
                switch (result.TopConfidence)
                {
                case RecognitionConfidence.Poor:
                    probability = .1F;
                    break;

                case RecognitionConfidence.Intermediate:
                    probability = .5F;
                    break;

                case RecognitionConfidence.Strong:
                    probability = .9F;
                    break;
                }
            }

            // Update the shape to reflect these results
            if (debug)
            {
                Console.WriteLine("Found input/output label: " + shapeName + " (confidence = " + probability + ")");
            }
            shape.setRecognitionResults(LogicDomain.TEXT, probability, shapeName);
        }
예제 #2
0
        /// <summary>
        /// Read a shape as text
        /// </summary>
        /// <param name="shape">the shape to recognize</param>
        /// <param name="confidence">how confident the reading is</param>
        /// <returns>the text string</returns>
        public string read(Sketch.Shape shape, out double confidence)
        {
            // Prepare the shape for recognition
            SketchOrInkConverter converter = new SketchOrInkConverter();

            _microsoftTextRecognizer.Strokes = converter.convertToInk(shape);

            // Try to recognize the shape
            RecognitionStatus status;
            RecognitionResult result;

            lock (_microsoftTextRecognizer)
            {
                result = _microsoftTextRecognizer.Recognize(out status);
            }

            // Origanize the results
            string shapeName = "";

            confidence = 0;
            if ((result != null) && (status == RecognitionStatus.NoError))
            {
                shapeName = result.TopString;
                switch (result.TopConfidence)
                {
                case RecognitionConfidence.Poor:
                    confidence = .1;
                    break;

                case RecognitionConfidence.Intermediate:
                    confidence = .5;
                    break;

                case RecognitionConfidence.Strong:
                    confidence = .9;
                    break;
                }
            }

            return(shapeName);
        }