fr.lri.swingstates.gestures.rubine
Class RubineClassifier

java.lang.Object
  extended by fr.lri.swingstates.gestures.AbstractClassifier
      extended by fr.lri.swingstates.gestures.rubine.RubineClassifier

public class RubineClassifier
extends AbstractClassifier

A classifier that implements rubine's algorithm to classify gestures.

Author:
Caroline Appert

Field Summary
static java.lang.String[] NAME_FEATURES
           
static int PF_ATH
          index of sum of absolute values of angles traversed) in a vector of features.
static int PF_BB_LEN
          index of length of bounding box diagonal in a vector of features.
static int PF_BB_TH
          index of angle of bounding box diagonal in a vector of features.
static int PF_DUR
          index of path duration in a vector of features.
static int PF_INIT_COS
          index of cosinus initial angle (angle between first and third points) in a vector of features.
static int PF_INIT_SIN
          index of sinus initial angle (angle between first and third points) in a vector of features.
static int PF_LEN
          index of arc length of path in a vector of features.
static int PF_MAXV
          index of maximum speed in a vector of features.
static int PF_SE_COS
          index of cosinus of angle between start and end points in a vector of features.
static int PF_SE_LEN
          index of length between start and end points in a vector of features.
static int PF_SE_SIN
          index of sinus of angle between start and end points in a vector of features.
static int PF_SQTH
          index of sum of squares of angles traversed) in a vector of features.
static int PF_TH
          index of total angle traversed in a vector of features.
 
Constructor Summary
RubineClassifier()
           
 
Method Summary
 int addClass(java.lang.String className)
          Adds a class of gestures to this classifier.
 void addExample(java.lang.String className, Gesture example)
          Adds a gesture example to this classifier.
 java.lang.String classify(Gesture g)
          Recognizes a gesture.
 double getCurrentDistance()
           
 java.util.Vector<Gesture> getExamples(java.lang.String className)
          Returns the vector of gesture examples for a given class.
static java.util.Vector<java.lang.Double> getFeatures(Gesture g)
          Computes the vector of features for a gesture.
 java.util.Vector<java.lang.Double> getFeatures(java.lang.String className)
          Computes the vector of features for a given class of gestures.
static java.util.Vector<java.lang.Double> getFeatures(java.util.Vector<java.awt.geom.Point2D> points)
          Computes the vector of features for a list of points.
 int getMaximumDistance()
           
 int getNbGestureExamples(java.lang.String className)
           
 CPolyLine getRepresentative(java.lang.String className)
          Returns a graphical representation for a given class of gestures.
static RubineClassifier newClassifier(java.io.File filename)
          Builds a new classifier by loading its definition in a file.
static RubineClassifier newClassifier(java.lang.String file)
          Builds a new classifier by loading its definition in a file.
static RubineClassifier newClassifier(java.net.URL url)
          Builds a new classifier by loading its definition in a url.
 void removeClass(java.lang.String className)
          Removes a class of gestures from this classifier.
 void removeExample(Gesture gesture)
          Removes a gesture example from this classifier.
 void renameClass(java.lang.String previousClassName, java.lang.String newClassName)
          Renames a class of gestures.
 void reset()
          Resets this classifier (i.e.
 void setMaximumDistance(int dist)
          Sets a maximum distance threshold for recognition.
 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
getClassesNames, getTemplate, getTemplates, save, setTemplate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PF_INIT_COS

public static int PF_INIT_COS
index of cosinus initial angle (angle between first and third points) in a vector of features.


PF_INIT_SIN

public static int PF_INIT_SIN
index of sinus initial angle (angle between first and third points) in a vector of features.


PF_BB_LEN

public static int PF_BB_LEN
index of length of bounding box diagonal in a vector of features.


PF_BB_TH

public static int PF_BB_TH
index of angle of bounding box diagonal in a vector of features.


PF_SE_LEN

public static int PF_SE_LEN
index of length between start and end points in a vector of features.


PF_SE_COS

public static int PF_SE_COS
index of cosinus of angle between start and end points in a vector of features.


PF_SE_SIN

public static int PF_SE_SIN
index of sinus of angle between start and end points in a vector of features.


PF_LEN

public static int PF_LEN
index of arc length of path in a vector of features.


PF_TH

public static int PF_TH
index of total angle traversed in a vector of features.


PF_ATH

public static int PF_ATH
index of sum of absolute values of angles traversed) in a vector of features.


PF_SQTH

public static int PF_SQTH
index of sum of squares of angles traversed) in a vector of features.


PF_DUR

public static int PF_DUR
index of path duration in a vector of features.


PF_MAXV

public static final int PF_MAXV
index of maximum speed in a vector of features.

See Also:
Constant Field Values

NAME_FEATURES

public static java.lang.String[] NAME_FEATURES
Constructor Detail

RubineClassifier

public RubineClassifier()
Method Detail

newClassifier

public static RubineClassifier 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 RubineClassifier 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.

newClassifier

public static RubineClassifier 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.

reset

public void reset()
Resets this classifier (i.e. removes all the classes of gestures).

Overrides:
reset in class AbstractClassifier

removeClass

public void removeClass(java.lang.String className)
Removes a class of gestures from this classifier.

Overrides:
removeClass in class AbstractClassifier
Parameters:
className - The name of the class of gestures to remove.

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.

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 class of gestures that best fit to g.

addClass

public int addClass(java.lang.String className)
Adds a class of gestures to this classifier.

Overrides:
addClass in class AbstractClassifier
Parameters:
className - The name of the class of gestures to add.
Returns:
the index of this class in the list of classes (-1 if this class already exists and thus has not been added).

getFeatures

public java.util.Vector<java.lang.Double> getFeatures(java.lang.String className)
Computes the vector of features for a given class of gestures.

Parameters:
className - The name of the class of gesture.
Returns:
The vector of features for the className class of gestures, null if this class does not exist.

getNbGestureExamples

public int getNbGestureExamples(java.lang.String className)
Parameters:
className - The name of the class of gesture.
Returns:
The number of examples in className class of gestures, -1 if this class does not exist..

getCurrentDistance

public double getCurrentDistance()
Returns:
The distance of the last recognized gesture to the average vector of its gesture class.

setMaximumDistance

public void setMaximumDistance(int dist)
Sets a maximum distance threshold for recognition. If the distance to the average vector of the closest gesture class is higher than distance threshold, the gesture is non recognized (i.e. method classify returns null). By default, this distance is set to 1000.

Parameters:
dist - The maximum distance to the average vector of recognized class.

getMaximumDistance

public int getMaximumDistance()
Returns:
The maximum distance threshold for recognition

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).

getFeatures

public static java.util.Vector<java.lang.Double> getFeatures(Gesture g)
Computes the vector of features for a gesture.

Parameters:
g - The gesture
Returns:
The vector of features.

getFeatures

public static java.util.Vector<java.lang.Double> getFeatures(java.util.Vector<java.awt.geom.Point2D> points)
Computes the vector of features for a list of points. Since we do not have time information, features related to time are set to NaN (path duration and maximum speed).

Parameters:
points - The list of points
Returns:
The vector of features.

removeExample

public void removeExample(Gesture gesture)
Removes a gesture example from this classifier.

Specified by:
removeExample in class AbstractClassifier
Parameters:
gesture - the gesture to remove

addExample

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

Specified by:
addExample in class AbstractClassifier
Parameters:
className - the gesture example's class
example - the gesture example

renameClass

public void renameClass(java.lang.String previousClassName,
                        java.lang.String newClassName)
Renames a class of gestures.

Overrides:
renameClass in class AbstractClassifier
Parameters:
previousClassName - The current name of this class of gestures
newClassName - The new name of this class of gestures

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