Penlets.com provides resources for users and developers of the Pulse smart pen from LiveScribe.
Subscribe: RSS Feed - Developers Group
Tutorial
Using Intelligent Character Recognition (ICR)
Tutorial by Robert HansonPage 1 » Page 2
One of the hot API features for developers is the ICR or Intelligent Content Recognition. It lets your application understand the words that are being written while they are being written. This is a cool feature and the API makes this relatively easy to accomplish. In this tutorial we will use this feature to take as input what the user is writing and display it as text in the Pen's OLED display.
Before we jump into the code I want to offer up a few terms to commit to memory. They will be useful to you as you start using the API.
Lexicon or Lex for short, is a set of words, a language if you will. The lexicon of a fast food joint would include "fries", "hamburger", but not "Courvoisier". In your project you make use of a lexicon that has been compiled into a Lexicon Knowledge Resource, or "LK" Resource for short. An LK resource contains more than just the words in the lexicon, it also contains other information like the frequency of specific letters. The pre-release API ships with several LK resource files, including one for a 100,000 word lexicon.
Now as well all know, words are made up of letters, and the set of letters used in a language is called an alphabet. In your project you will need to define the alphabet by supplying an Alphabet Knowledge Resource, or "AK" Resource for short (not to be confused with the "AK" Russian made assault rifle). If you think this means that you can use a non-Latin alphabet, don't get your hopes up quite yet, the SDK currently only supports a single "default" AK resource right now. You can though specify a cursive alphabet if you desire.
So far so good, a "LK" resource defines the lexicon, and the "AK" resource defines the alphabet. But what if you are writing a program that only uses numbers and symbols, like a math solving program? In that case you would want to use only a subset of the alphabet (numbers + symbols). In your project you accomplish this by specifying a Subset Knowledge Resource, or "SK" Resource. The pre-release API comes with SK resources for letters, numbers, punctuation, lower-case, and upper-case.
Lastly we take the "AK", "SK", and "LK" resources and throw them into a bucket called the ICR Context. ICR is the acronym for Intelligent Character Recognition. The ICR context has the job of recognizing words that are written. In order to accomplish this grandiose task you need to first provide it with the resource objects that we have discussed, then as the user of the pen writes you will need to feed the ICR context the strokes that are created. As you feed the ICR content with the strokes it continuously attempts to match the strokes to characters, and the characters to words. Once the ICR Context detects a pause in the stroke input it will then let you know what was written (to the best of its "LK", "AK", and "SK" knowledge). This act of recognizing what has been written is Hand Writing Recognition or "HWR" for short.
Ok, now let's get to the code. Our task is simple. Create an ICR Context, define the resources, and add event handling so that we can provide the ICR Context with strokes and the ICR Context can provide us with words.
We will be creating only one class file in this tutorial, and will provide little bits at a time. Here we start with a simple base.
package com.penlets.icr;
import com.livescribe.afp.PageInstance;
import com.livescribe.display.Display;
import com.livescribe.event.HWRListener;
import com.livescribe.event.StrokeListener;
import com.livescribe.icr.ICRContext;
import com.livescribe.icr.Resource;
import com.livescribe.penlet.Penlet;
import com.livescribe.penlet.PenletStateChangeException;
import com.livescribe.penlet.Region;
import com.livescribe.ui.ScrollLabel;
public class CopyOfICRDemo extends Penlet
{
private Display display;
private ScrollLabel label;
private ICRContext icrContext; /* [1] */
/**
* This must be set to true in order to recieve
* stroke events.
*/
public boolean canProcessOpenPaperEvents () /* [2] */
{
return true;
}
/* ***********************************************
*
* Abstract methods of Penlet.
*
*********************************************** */
public void initApp () throws PenletStateChangeException
{
this.display = this.context.getDisplay();
this.label = new ScrollLabel();
}
public void activateApp (int reason, Object[] args)
{
this.label.draw("Write something", true);
this.display.setCurrent(this.label);
initICRContext(); /* [3] */
}
public void deactivateApp (int reason) {
destroyICRContext(); /* [4] */
}
public void destroyApp () throws PenletStateChangeException { }
}
Here we start with the usual stuff. A simple class that extends Penlet, and displays "Write Something" in the display of the pen when the application is started.
In addition to the basic boilerplate code we have a few additions. We
have added a field
icrContext
[1] to hold our ICR Context (obviously), which we
will use a little later. Next we override the method
canProcessOpenPaperEvents
[2], returning true. We need this to tell the pen
that we want to receive stroke events. If you forget this we won't
have any strokes to feed the ICR Context, so don't forget it! And
lastly we have included calls to
initICRContext
[3] and
destroyICRContext
[4], which we have not yet defined. Note that as a
convenience we have also included all of the imports that we will use
throughout this tutorial, even though we are not using them quite
yet. Next Page »
Page 1 » Page 2
Comments (View) blog comments powered by Disqus
Project Information
Tested for use with: PreRelease-SDK 0.6
Download the source code for this tutorial.
Download Source Code (zip)
New Tutorials
Using a Shared Library
Learn how to create a library of utils that you can
share between projects.
Capturing Drawn Shapes
Learn how to capture shapes drawn by the pen and determine relationships.
Penlets 101
Never written a penlet before? Then start here with Penlets 101!
Creating a Custom Vocabulary
Learn how to create a custom vocabulary for your ICR applications.
Using Properties Files
J2ME lacks a Properties class. In this tutorial we roll our own,
along with split and chomp functions.