Welcome to MSDN Blogs Sign in | Join | Help

Tablet PC: How to improve handwriting recognition accuracy using Factoids and the RecognizerContext

In my last few posts I have been demonstrating the use of the RecognizerContext class to perform basic handwriting recognition on the Tablet PC. We have taken a look at basic synchronous recognition, basic asynchronous recognition, and recognition with alternates. Those are a few of the common handwriting recognition scenarios. Once you have hooked up handwriting recognition in your Ink-enabled application, you may find out that your handwriting recognition accuracy is lacking. If this is the case, using the Factoid property of the RecognizerContext class could be a good solution to improve your handwriting recognition accuracy.

The RecognizerContext.Factoid property is a string member that provides contextual information to the RecognizerContext when performing handwriting recognition. Essentially, by setting the Factoid string, you are telling the recognizer what your ink is. If we have a form with an inking area where the ink is recognized and converted to a text web address, the ink IS a web address. It just so happens that WEB is one of the predefined Factoid strings.

Examples of setting the Factoid:

// Instantiate a RecognizerContext object

RecognizerContext context = new RecognizerContext();

 

// Use a static string property of the Factoid class

context.Factoid = Factoid.Web;

 

// Use a string literal

context.Factoid = "WEB";

 

// Use one of the supported Factoid combinations

// for Western languages only

context.Factoid = "WEB|WORDLIST";

 

Note that it’s good practice to enclose the setting of the Factoid property in a try-catch block because some recognizers do not support some Factoids. (See link to msdn article below for more info)

 

Some predefined Factoid strings:

Factoid.Currency      

Factoid.Date          

Factoid.Digit         

Factoid.Email         

Factoid.Filename 

Factoid.LowerChar 

Factoid.None 

Factoid.Number 

Factoid.NumberSimple 

Factoid.OneChar 

Factoid.Percent 

Factoid.PostalCode 

Factoid.Telephone 

Factoid.Time 

Factoid.UpperChar 

Factoid.Web 

Factoid.WordList 

Currency, such as $19.99

Date, such as 12/12/2005

Digit, such as 6

Email address such as foo@foo.com

Filename, such as C:\file.txt

Lower case character such as a

No factoid

Number, such as 6e-12

Simple number such as 1024

One character such as A

Percentage such as 99%

Postal code, such as 98072

Telephone number such as 1-800-999-9999

Time such as 4:45pm

Upper case character such as A

Web address such as http://www.microsoft.com

The RecognizerContext will use the WordList property and return a value from that wordlist

 

So let’s take a look at what adding Factoid support to our basic ink application would look like. It can be as simple as setting the RecognizerContext.Factoid property. See the following example code:

//

// Basic Ink enabled Windows Forms application with

// handwriting recognition using RecognizerContext

// Gavin Gear - http://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)

        {

            // Instantiate a RecognizerContext object

            RecognizerContext context = new RecognizerContext();

 

            // Use a static string property of the Factoid class

            context.Factoid = Factoid.Web;

 

            // 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);

 

            MessageBox.Show(result.TopString);

 

            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:

 

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

 

For more information of Factoids see the msdn article:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tpcsdk10/lonestar/microsoft.ink/Classes/recognizercontext/Properties/factoid.asp

 

Using Factoids can greatly enhance your handwriting recognition scenarios. Next time I’ll demonstrate how to use the WordList factoid which enables you to specify the acceptable recognition strings returned by the recognizers.

 

See Ya-

Gavin

Published Tuesday, August 29, 2006 10:11 AM by GavinGear

Comments

No Comments

Anonymous comments are disabled
 
Page view tracker