fr.lri.swingstates.gestures.shapeMatching
Class ShapeMatchingClassifier

java.lang.Object
  extended by fr.lri.swingstates.gestures.AbstractClassifier
      extended by fr.lri.swingstates.gestures.shapeMatching.ShapeMatchingClassifier

public class ShapeMatchingClassifier
extends AbstractClassifier

A very simple recognizer that performs simple shape matching based on a single example per class (one template):

  1. Resample the gesture to classify so it contains the number of uniformly spaced points as the gesture templates contained in this classifier.
  2. For each template, scale the input gesture so its bounding box matches the bounding box of the template and compute the sum of distances point to point between the template points and the input gesture points.
  3. Returns the name of the class for the template that minimizes this sum of distances.

Author:
Caroline Appert

Constructor Summary
ShapeMatchingClassifier()
           
 
Method Summary
 void addClass(java.lang.String className, java.util.Vector<java.awt.geom.Point2D> template)
          Adds a class and set the template for this class.
 void addExample(java.lang.String className, Gesture example)
          Adds a gesture example to this classifier.
 java.lang.String classify(Gesture g)
          Recognizes a gesture.
 NamedGesture classifyAndResample(Gesture g)
          Classifies a gesture and return the collection of resampled points for the input gesture.
 java.util.Vector<Gesture> getExamples(java.lang.String className)
          Returns the vector of gesture examples for a given class.
 int getMinimumStrokeLength()
           
 int getNbPoints()
           
 CPolyLine getRepresentative(java.lang.String className)
          Returns a graphical representation for a given class of gestures.
 double getSizeScaleToSquare()
           
 double getThreshold()
           
static ShapeMatchingClassifier newClassifier(java.io.File filename)
          Builds a new classifier by loading its definition in a file.
static ShapeMatchingClassifier newClassifier(java.lang.String file)
          Builds a new classifier by loading its definition in a file.
static ShapeMatchingClassifier newClassifier(java.net.URL url)
          Builds a new classifier by loading its definition in a url.
 void removeExample(Gesture gesture)
          Removes a gesture example from this classifier.
 void save(java.io.File filename)
          Saves the definition of this classifier in a file.
 void setMinimumStrokeLength(int minimumStrokeLength)
           
 void setSizeScaleToSquare(int size)
          The side size of the bounding box to which the gesture is scaled after having being resampled.
 void setTemplate(java.lang.String className, java.util.Vector<java.awt.geom.Point2D> template)
          Sets the template gesture for a given existing class of gestures in this classifier.
 void setThreshold(double maximumDistance)
           
 java.util.Vector<Score> sortedClasses(Gesture g)
          Computes a sorted list of classes contained in this recognizer from the best match to the the worst match given a gesture.
 
Methods inherited from class fr.lri.swingstates.gestures.AbstractClassifier
addClass, getClassesNames, getTemplate, getTemplates, removeClass, renameClass, reset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeMatchingClassifier

public ShapeMatchingClassifier()
Method Detail

classify

public java.lang.String classify(Gesture g)
Recognizes a gesture.

Specified by:
classify in class AbstractClassifier
Parameters:
g - The gesture to recognize
Returns:
The name of the class of gestures that best fit to g.

classifyAndResample

public NamedGesture classifyAndResample(Gesture g)
Classifies a gesture and return the collection of resampled points for the input gesture.

Parameters:
g - The input gesture.
Returns:
a NamedGesture that contains the name of the recognized class and the set of resampled points.

newClassifier

public static ShapeMatchingClassifier newClassifier(java.lang.String file)
Builds a new classifier by loading its definition in a file.

Parameters:
file - The name of the file containing the definition of the classifier.
Returns:
The newly created classifier.

newClassifier

public static ShapeMatchingClassifier newClassifier(java.io.File filename)
Builds a new classifier by loading its definition in a file.

Parameters:
filename - The name of the file containing the definition of the classifier.
Returns:
The newly created classifier.

newClassifier

public static ShapeMatchingClassifier newClassifier(java.net.URL url)
Builds a new classifier by loading its definition in a url.

Parameters:
url - The url containing the definition of the classifier.
Returns:
The newly created classifier.

addClass

public void addClass(java.lang.String className,
                     java.util.Vector<java.awt.geom.Point2D> template)
Adds a class and set the template for this class.

Parameters:
className - The name of the class to add
template - The template for the class className

sortedClasses

public java.util.Vector<Score> sortedClasses(Gesture g)
Computes a sorted list of classes contained in this recognizer from the best match to the the worst match given a gesture.

Specified by:
sortedClasses in class AbstractClassifier
Parameters:
g - The gesture
Returns:
a vector of scores for all the classes registered in this classifier sorted from the best match (index 0) to the worst match (index n-1), with n the number of classes. A score is a couple (class_name, distance).

getNbPoints

public int getNbPoints()

getSizeScaleToSquare

public double getSizeScaleToSquare()

save

public void save(java.io.File filename)
Saves the definition of this classifier in a file.

Overrides:
save in class AbstractClassifier
Parameters:
filename - The name of the file where to write the definition of the classifier.

getRepresentative

public CPolyLine getRepresentative(java.lang.String className)
Returns a graphical representation for a given class of gestures. The graphical representation is the one which minimizes the distance with vector of features characterizing this gesture class.

Specified by:
getRepresentative in class AbstractClassifier
Parameters:
className - the name of the gesture class.
Returns:
A representative polyline for the gesture class having name className.

removeExample

public void removeExample(Gesture gesture)
                   throws java.lang.UnsupportedOperationException
Removes a gesture example from this classifier.

Specified by:
removeExample in class AbstractClassifier
Parameters:
gesture - the gesture to remove
Throws:
java.lang.UnsupportedOperationException

addExample

public void addExample(java.lang.String className,
                       Gesture example)
                throws java.lang.UnsupportedOperationException
Adds a gesture example to this classifier.

Specified by:
addExample in class AbstractClassifier
Parameters:
className - the gesture example's class
example - the gesture example
Throws:
java.lang.UnsupportedOperationException

getExamples

public java.util.Vector<Gesture> getExamples(java.lang.String className)
                                      throws java.lang.UnsupportedOperationException
Returns the vector of gesture examples for a given class.

Specified by:
getExamples in class AbstractClassifier
Parameters:
className - The name of the class
Returns:
The set of examples for the class className.
Throws:
java.lang.UnsupportedOperationException

setSizeScaleToSquare

public void setSizeScaleToSquare(int size)
The side size of the bounding box to which the gesture is scaled after having being resampled.

Parameters:
size - The side size of the bounding box

setTemplate

public void setTemplate(java.lang.String className,
                        java.util.Vector<java.awt.geom.Point2D> template)
Sets the template gesture for a given existing class of gestures in this classifier.

Overrides:
setTemplate in class AbstractClassifier
Parameters:
className - the name of the class of gestures.
template - the template for the class className.

getThreshold

public double getThreshold()

setThreshold

public void setThreshold(double maximumDistance)

getMinimumStrokeLength

public int getMinimumStrokeLength()

setMinimumStrokeLength

public void setMinimumStrokeLength(int minimumStrokeLength)