Dela via


How To: Using Recognition Alternates in the Tablet PC SDK using RecognizerContext

Now that we've taken a look at how to perform handwriting recognition with the Tablet PC Platform SDK 1.7 (See https://blogs.msdn.com/gavingear/archive/2006/08/22/713189.aspx), let's dig a bit deeper and take a look at "recognition alternates"

When ink is processed by the handwriting recognition engines, there are two basic steps that are performed:

  1. The possible segmentations are determined. Segmentation is the process of breaking handwritten strokes into individual words. Since there are several possibilities for each stroke collection, there can be multiple segmentations stored for the recognition of more than one stroke (Example: Together could be To get her, Together, etc). See screenshot attachment for an example of this.
  2. For each segmentation, the possible recognition strings are calculated

The combination of steps 1 and 2 above produces a list of "Alternates" which are a list of possible recognition results for the ink processed. The alternates are ranked by a confidence score (most accurate on the top) - and the list of alternates can be obtained from the RecognitionResult returned from RecognizerContext.Recognize().

In the following example, I present a list of alternates to the user following handwriting recognition:

//

// Basic Ink enabled Windows Forms application with

// handwriting recognition using RecognizerContext

// Gavin Gear - https://blogs.msdn.com/gavingear

// 08/2006

//

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using Microsoft.Ink; // The managed Tablet PC API

namespace BasicInkApplication

{

    public partial class BasicInkApplication : Form

    {

        // The InkOverlay that we'll attach to our Form

        private InkOverlay inkOverlay;

        public BasicInkApplication()

        {

            InitializeComponent();

            // Create an InkOverlay object that's attached to the Form

            this.inkOverlay = new InkOverlay(this);

            // Enable the InkOverlay (default is Enabled == false)

            this.inkOverlay.Enabled = true;

            // The InkOverlay needs to be disposed due to unmanaged resources

            // used by the InkOverlay

            this.FormClosing += new FormClosingEventHandler(BasicInkApplication_FormClosing);

        }

        void BasicInkApplication_FormClosing(object sender, FormClosingEventArgs e)

        {

            this.inkOverlay.Dispose();

        }

        private void buttonRecognize_Click(object sender, EventArgs e)

        {

            if (this.inkOverlay.Ink.Strokes.Count > 0)

            {

                // Instantiate a RecognizerContext object

                RecognizerContext context = new RecognizerContext();

                // Add the strokes collected by our InkOverlay

                context.Strokes = this.inkOverlay.Ink.Strokes;

                // Perform recognition, pass a RecognitionStatus object

                // that will give the status of the recognition

         RecognitionStatus status;

                RecognitionResult result = context.Recognize(out status);

                RecognitionAlternates alternates = result.GetAlternatesFromSelection();

                string alternatesString = "";

             foreach (RecognitionAlternate alternate in alternates)

                {

                    alternatesString += alternate.ToString() + Environment.NewLine;

                }

                MessageBox.Show(alternatesString, "Alternates from recognition");

                context.Dispose(); // Free the unmanaged resources

            }

        }

    }

}

**Note that on non-Tablet PC OS platforms, you'll need to install the recognizer pack, otherwise the RecognizerContext object will throw an exception when it is instantiated. You can download the recognizer pack from the following location:

https://www.microsoft.com/downloads/details.aspx?FamilyID=080184dd-5e92-4464-b907-10762e9f918b&DisplayLang=en

Note that you can also access properties such as the "confidence" for each alternate. One of the common uses for alternates to implement a correction UI for an Ink-enabled application. I should also note here that there are overloads for GetAlternatesFromSelection() that allow you to do things like specify the maximum number of alternates to retrieve.

That's your basic into to RecognitionAlternates!

See ya-
Gavin

reco_alternates.bmp

Comments

  • Anonymous
    August 25, 2006
    So far, I have illustrated a couple basic handwriting recognition scenarios using the RecognizerContext...