Tablet PC: Getting started with InkAnalysis – basic handwriting recognition

I’ve spent the last few weeks blogging about existing APIs in the Tablet PC Platform SDK related to handwriting recognition and layout analysis of ink. Now, I’m going to start talking about the new InkAnalysis API which better integrates the two, and offers much more functionality.

In this post last month:
https://blogs.msdn.com/gavingear/archive/2006/08/22/713189.aspx
I demonstrated how to perform basic handwriting recognition using the RecognizerContext object. In this post, we’ll take a look at using an InkAnalyzer in a Windows Forms application to do the same thing.

Before getting started, you’ll want to read my last post regarding prepping your dev box for InkAnalysis development:
https://blogs.msdn.com/gavingear/archive/2006/09/06/743377.aspx

OK, let’s get to it! Here’s what we’ll do to create a simple reco application:

1. Create a new project (Windows Forms application)

2. Add a reference to: %ProgramFiles%\Reference Assemblies\Microsoft\Tablet PC\v1.7\Microsoft.Ink.Analysis.dll

3. Add a button and button click handler (You can just double click on the button in the designer, and it will generate a click handler and browse to it)

4. Add an InkOverlay, attach it to the form, and enable it

5. In the click handler, instantiate an InkAnalyzer which references the InkOverlay’s Ink object for the ink source and the form (this) for the synchronizing object (more on that later)

6. Add the current strokes from the InkOverlay to the InkAnalyzer

7. Call InkAnalyzer.Analyze()

8. Get the top recognition result for the strokes by calling InkAnalyzer.GetRecognizedString()

9. Display the result to the user

10. Dispose the InkAnalyzer

Code:

 //

// Basic Ink enabled Windows Forms application with

// handwriting recognition using InkAnalyzer

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

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

        {

            InkAnalyzer analyzer = new InkAnalyzer(this.inkOverlay.Ink, this);

            analyzer.AddStrokes(this.inkOverlay.Ink.Strokes);

            AnalysisStatus status = analyzer.Analyze();

            MessageBox.Show(analyzer.GetRecognizedString());

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

       }

    }

}

 

There you have it- a basic InkAnalysis handwriting recognition application. This example mirrors what I implemented in the RecognizerContext basic recognition application, but there’s a whole lot more that we can do with InkAnalysis, we’ll take a look at various features and capabilities bit by bit.

See Ya,
Gavin