How To: Perform basic handwriting recognition with the RecognizerContext object
In my last post I created a basic Windows Forms project that references the Tablet PC API (1.7) and utilizes an InkOverlay to collect ink. In this post, I'm going to hook up basic handwriting recognition using the RecognizerContext object. You will want to read the last post if you are planning on following this example.
https://blogs.msdn.com/gavingear/archive/2006/08/21/711313.aspx
Step 1: Add a button, and click handler
- Open the project from the previous post (see link above)
- Drag a button from the toolbox onto your form
- Change the text to "Recognize" and the name to "buttonRecognize" in the properties window
- Double click on the button in the designer to add a click handler
Step 2: Implement the recognition code in the click handler
// // 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) { // 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); 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:
This is all you need to perform basic handwriting recognition. (See attached screenshot) Note that you should check the status object to make sure it has the value: RecognitionStatus.NoError in order to ensure Recognition was successful. If this value is not returned, you should handle the error appropriately. You can also get alternates (best guesses) to allow the user to correct the recognition.
See ya!
Gavin
Comments
- Anonymous
August 24, 2006
Now that we've taken a look at how to perform handwriting recognition with the Tablet PC Platform SDK... - Anonymous
August 25, 2006
So far, I have illustrated a couple basic handwriting recognition scenarios using the RecognizerContext... - Anonymous
September 07, 2006
I’ve spent the last few weeks blogging about existing APIs in the Tablet PC Platform SDK related to handwriting...