Browse DevX
Sign up for e-mail newsletters from DevX


Creating Tablet PC Applications with VS .NET : Page 6

The Tablet PC platform supports applications with special tablet features enabled, such as ink input and pen-based operation. In order for this platform to become truly popular, third-party vendors will also have to ink-enable their applications. Find out how.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Ink Recognition
Of course, ink is not always useful as ink. Often, you will be interested in a textual representation of the user's handwriting. Or perhaps you would like to interpret the ink as graphical shapes such as rectangles and circles. Other uses may call for the ink to be recognized as symbols, mathematical formulae, or even musical notes. And beyond that, certain scribbles may need to be interpreted as gestures that instruct the operating system or the application to perform certain tasks.

The Tablet PC operating system ships with a number of recognizers. The most frequently used recognizer (the default recognizer) recognizes text in the Tablet PC's native language, such as English. Another recognizer that ships with all Tablet PCs is the gesture recognizer. More sophisticated or more specialized recognizers must be installed manually. (Developing handwriting recognizers is certainly beyond the scope of this article.)

Ink recognition (also known as "ink reco") is surprisingly easy using the Tablet PC SDK. In fact, retrieving the most likely recognition result using the default recognizer is simple. For instance, if you wanted to recognize all the text written, you could simply call the ToString() method on the Strokes collection:


That's it! You can wire this code to a button on the ink notepad form, and try it out every so often. You'll be surprised how well it works.

There are, of course, more sophisticated scenarios. Perhaps you are interested in alternate recognition results or just different spacing options (is it "Visual Studio.NET" or "Visual Studio .NET"?). Or perhaps you would like to use a recognizer other than the default. Either way, you would have to manually obtain a recognizer context that grants access to many more details. Here's how that's done:

Recognizers oRecognizers = new Recognizers(); Recognizer oReco = Recognizers.GetDefaultRecognizer(); RecognizerContext oRC = oReco.CreateRecognizerContext();

In this case, you obtain a manual reference to the default recognizer, but you could have also selected a specific recognizer instead. Once you pick a recognizer, you start a new recognizer context, and are ready to go.

Once again, the recognizer context works based on a Strokes collection. The first step in manual recognition is to attach a Strokes collection to the context, and then indicate that no more input is to be expected. Note that recognizers have the ability to recognize text asynchronously, a few words (or strokes) at a time. In this case, you could add Strokes collections to the context until you are finished. In the example, you will only recognize relatively small amounts of text, and you'll do so all at once. For this reason, you call the EndInkInput() method right after you assign the Strokes collection:

oRC.Strokes = oInk.Ink.Strokes; oRS.EndInkInput();

Now, you can retrieve recognition results using the context's Recognize() method, which also takes one parameter by reference and tells us whether the recognition works as expected:

RecognitionStatus iStat = RecognitionStatus.NoError; RecognitionResult oResult = oRC.Recognize(iStat);

At this point, you have a Result object that contains all types of information about the text recognition attempt. The most useful information (which is the same as the information retrieved by the ToString() method above) is known as the TopAlternate. But this time, not only do you have access to the result string, but also additional information such as the recognition confidence level. Here is an example that uses this information:

if (oResult.TopAlternate.Confidence == RecognitionConfidence.Strong) { MessageBox.Show( Result.TopAlternate.ToString()); }

Similarly, you could access alternate recognition results and retrieve their text and additional attributes. Using manual recognition is not only useful because you have access to more information about the results, but also because you can provide the recognizer with additional hints about the text you are attempting to recognize. For instance, you may want to recognize only numbers. In this case, you can set a recognition factoid:

oRC.Factoid = "Number";

This drastically limits the number of possible results and will therefore improve recognition quality considerably. The provided recognizers support a large number of factoids (such as "date" and "phone number"), and they can be combined at will.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date