Guide #4: Using the PaleoSketch recognizer library


Below are some instructions provided by Marty Field on how to work with the PaleoSketch recognizer library. These instructions will allow you to better understand how to use them for the sketch data that you are working with.

**********

Attached is a JAR containing Paleo Sketch and its dependencies. The JAR can be used as a library in your project, or you can extract it and use the enclosed source if you find the need to modify anything. We don't have much documentation prepared outside the comments in the code, so I'll give a brief overview of the contents and how to use Paleo here:

The bulk of the code is in the edu.tamu package. The org.ladder package provides us some backwards compatibility and is required to build, but you can mostly ignore it. The hhreco package is a dependency of Paleo that you don't need to interact with directly, either.

edu.tamu.core.sketch contains all of the data structures we use to represent a sketch. A Point is the most basic unit composed of X, Y, and time. A Stroke typically represents the time between putting the pen down and lifting it up again, it boils down to an ordered collection of Points. A Shape is a group of other components (Points, Strokes, Shapes) that logically belong together. Finally, a Sketch is really just a big Shape used to encapsulate a whole drawing.

edu.tamu.recognition.paleo.PaleoSketchRecognizer is the main class that provides access to Paleo's functionality. When you instantiate a PaleoSketchRecognizer, you specify which primitive shapes should be turned on or off. Using fewer primitives usually results in higher accuracy and lower recognition time. edu.tamu.recognition.paleo.PaleoConfig contains some static functions that generate configurations you can use as templates, for example my current project uses PaleoConfig.civilSketchConfig().
Instantiating a PaleoSketchRecognizer is a very expensive operation, so you will want to create one when your program initializes and reuse the same one for the lifetime of the application.

The input to Paleo is a single Stroke, and the output is a list of Shapes. Each Shape in the list is a possible interpretation for the Stroke. For example, a Stroke might be a Rectangle with confidence 75% or an Ellipse with confidence 50%. This information is stored in the Shape's Interpretation, which is a pair of a label, like "Rectangle" or "Ellipse" and a confidence value (typically between 0 and 1.0). A simple example to recognize a Stroke named someStroke:

PaleoSketchRecognizer paleo = new PaleoSketchRecognizer(PaleoConfig.allOn());
...
paleo.setStroke(someStroke);
Shape bestMatch = paleo.recognize().getBestShape();
...
String shapeName = shape.getInterpretation().label;
if(shapeName.equals("Square")) ...

Finally, there is a very simple application in edu.tamu.core.gui.TestApplication, which demonstrates basically how we usually collect and display pen input data. To save and load sketches, we use a really cool serialization package written by our friends the Interface Ecology Lab (ecologylab.net) called S.IM.PL (http://ecologylab.net/research/simpl/index.html). Simpl is in active development, but the attached JAR contains a build that has worked very well for us. The newest source can be obtained through the ecologylab SVN following the instructions on their site. The TestApplication has some code for saving/loading sketches.