Professional Documents
Culture Documents
Pi19404
April 5, 2013
Contents
Contents
Android :Single Stroke Gesture Recognition using $1 Detector
0.1 Introduction . . . . . . . . . . . . . . . . . . . . . 0.2 $1 Unistroke Recognizer . . . . . . . . . . . . . 0.3 Gesture Normalization . . . . . . . . . . . . . . . 0.3.1 Registering candidate . . . . . . . . . . 0.3.2 Rejecting invalid Gesture . . . . . . . . 0.3.3 Re-sampling points . . . . . . . . . . . . . 0.3.4 Scaling . . . . . . . . . . . . . . . . . . . . . 0.3.5 Translation . . . . . . . . . . . . . . . . . . 0.4 Rotational Invariance . . . . . . . . . . . . . . . . 0.5 Rejecting gestures . . . . . . . . . . . . . . . . . 0.6 Robustness to rotation . . . . . . . . . . . . . . 0.7 Computing the Similarity Score . . . . . . . . . 0.7.1 Loading the Template Gestures . . . 0.7.2 Android Gesture Capture Application 0.8 Launch Application . . . . . . . . . . . . . . . . . 0.9 Code . . . . . . . . . . . . . . . . . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
3 3 4 4 5 5 7 7 8 8 9 9 10 12 12 12 12
2 | 13
3 | 13
Android :Single Stroke Gesture Recognition using $1 Detector gestures are drawn.
4 | 13
Android :Single Stroke Gesture Recognition using $1 Detector ordinate information of drawn gesture. contains instance of DataVector. The DataCapture Class
The class PUtils contains all the methods for gesture pre processing and recognition. The DataCapture class contains instance of PUtils class .
1 2 3 4 5 6 7 8 9
public double PathLength ( Vector points ) { double length = 0; for ( int i = 1; i < points . size () ; i ++) { length += Distance (( Point ) points . elementAt ( i - 1) , ( Point ) points . elementAt ( i ) ) ; } return length ; }
In the present implementation the path length threshold used in 100. The code is implemented by the method PathLength is the PUtils Class.
5 | 13
Android :Single Stroke Gesture Recognition using $1 Detector The re-sampling operations selects from the provided candidate/template gesture a fixed subset of points. This ensures than candidate and template have the same number of points enabling us to perform point based comparison. The method used for sampling the data points is uniform sampling.The path length is divided by the number of re-sampled points.This will be the interval length between the points. We start with the initial point and next point is selected such that distance between points is greater than of equal to interval length.Let points be labeled pt1 and pt2 A linear path is assume to exist between adjacent sample points. using simple trigonometric relationship of sin and cos we can estimate of location at distance of uniform path interval which lies between pt1 and pt2 . This new co-ordinate replaces pt2 in the candidate/template coordinate array and the same process is repeated till the last point of the co-ordinate array is reached.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
double d = Distance ( pt1 , pt2 ) ; if (( D + d ) >= I ) { // computation of new co - ordinate using cos relationship double qx = pt1 . x + ( I / ( D + d ) ) * ( pt2 . x - pt1 . x ) ; // computation of new co - ordinate using sin relationship double qy = pt1 . y + ( I / ( D + d ) ) * ( pt2 . y - pt1 . y ) ; Point q = new Point ( qx , qy ) ; // adding the point in resampled array dstPts . addElement ( q ) ; // replacing the point in the source array srcPts . insertElementAt (q , i ) ; // resetting cumulative distance D = 0.0; } else { // computing cumulative distance D=D+d; }
This is implemented by the method Re-sample in the PUtils Class. In the present implementation the number of re-sampled points
6 | 13
0.3.4 Scaling
The next pre-processing step is to scale the co-ordinates such that third width and height remain within a fixed bounds.First the bounding width and height of current set of points are computed which is simply max(x) min(x) and max(y ) min(y ).The new width and height are denoted by W and H and all the points are scaled by factor W=max(x) min(x) and H=max(y ) min(y )
1 2 3 4 5 6 7 8 9
Rectangle B = BoundingBox ( points ) ; Vector newpoints = new Vector ( points . size () ) ; for ( int i = 0; i < points . size () ; i ++) { Point p = ( Point ) points . elementAt ( i ) ; double qx = p . x * ( size / B . Width ) ; double qy = p . y * ( size1 / B . Height ) ; newpoints . addElement ( new Point ( qx , qy ) ) ; }
This provides step provides invariance wrt scaling since all gestures are bounded to lie within rectangle of same size.This is implements by method ScaleToSquare1 in PUtils class. In the present implementation the scale is done so than bounding box is a square of dimension 250. The above method perform uniform scaling another method of scaling is non uniform scaling that maintains the aspect ratio. Compute the ration between the width and height or viceversa of the bounding rectangle if ratio is close to 0 than 1 then perform non uniform scaling else perform uniform scaling. The ScaleDimTo method implements this in the PUtils Class.
0.3.5 Translation
The first step required is computation of mean/centroid of set of co-ordinate location.
1 2 3 4
7 | 13
xsum += p . x ; ysum += p . y ;
This is implemented by the method Centroid in class PUtils. The next step is to translate all the points such that centroid lies at the origin of co-ordinate system. Translate all the points by (centroidx ; centroidy ).
1 2 3 4 5 6 7 8 9
Point c = Centroid ( points ) ; Vector newpoints = new Vector ( points . size () ) ; for ( int i = 0; i < points . size () ; i ++) { Point p = ( Point ) points . elementAt ( i ) ; double qx = p . x - c . x ; double qy = p . y - c . y ; newpoints . addElement ( new Point ( qx , qy ) ) ; }
8 | 13
Android :Single Stroke Gesture Recognition using $1 Detector two points normalized by the distance between them.This vector is called StartUnitVector
1 2 3 4 5
Point i1 =( Point ) points . elementAt ( index ) ; Point i2 =( Point ) points . elementAt (0) ; Point v = new Point ( i1 . x - i2 .x , i1 . y - i2 . y ) ; double len = Math . sqrt ( v . x * v . x + v . y * v . y ) ; return new Point ( v . x / len , v . y / len ) ;
CalcStartUnitVector method of PUtils class computes this angle. To compare startunitvectors of template and candidate cosine of angle between the unit vectors is used as criteria The AngleBetweenUnitVectors method compute difference in angle
1 2
double n = ( v1 . x * v2 . x + v1 . y * v2 . y ) ; return Math . acos ( n ) ; // arc cosine of the vector dot product
9 | 13
Android :Single Stroke Gesture Recognition using $1 Detector As method earlier a scan of angle withing a specified range is performed. It is assumed that maximum score exits amongst the angle. Instead of performing a uniform search the Golden section search algorithm is used to search for global maximum from list of candidate by by successively narrowing the range of values inside which the maximum score is known to exist. The cost function or score is provided DistanceAtAngle function which computes the distance between the candidate rotated by specified angle and template.The score is compute by computing the euclidean distance between the 2D set of vectors. DistanceAtBestAngle method in PUtils Class compute the best score by applying golden section scan algorithm about range of specified angles. DistanceAtAngle method in PUtils Class performs transformation about the points such that all points are rotated by specified angle before comparison. PathDistance method in PUtils class computes the euclidean distance between the set of 2D points.
1 2 3 4 5 6
double distance = 0; for ( int i = 0; i < path1 . size () ; i ++) { distance += Distance (( Point ) path1 . elementAt ( i ) , ( Point ) path2 . elementAt ( i ) ) ; } return distance / path1 . size () ;
The Recognize method in PUtils class provides interface to gesture recognition routine.
10 | 13
Android :Single Stroke Gesture Recognition using $1 Detector directory.For each files a template object will be created. In the CSV files raw x and y co-ordinates of gesture trajectory of mouse pointer captured by desktop application are written side by side and this entire CSV string is loaded into a integer array.Hence while loading the template nth location is assigned to x co-ordinate while (n + 1)th location of integer array is assigned to y co-ordinate of 2D co-ordinate object representing Point Class. The templates are loaded once during initialization. Comparison is made with all the loaded templates and best score is selected amongst the templates. Below are examples of templates demonstrated in the present application.The template consist of following shapes made in clockwise and anti clockwise manner.The templates are labeled as (1,11) ,(2,12) ,(3,15) (9,13),(10,14) for clockwise and anticlockwise respectively. An example of data contained in CSV files is shown below
11 | 13
Android :Single Stroke Gesture Recognition using $1 Detector 142,140,147,143,150,147,153,150,155,152,157,155,158 This contains x and y co-ordinates stored in adjacent locations.
0.9 Code
The code can be found in code repository https://github.com/ pi19404/m19404/tree/master/Android/AndroidGesture or https://code. google.com/p/m19404/source/browse/Android/AndroidGesture. The header files is located in jni directory.The library files are not placed in the repository download them from appropriate packages on send a mail separately for download link.
12 | 13
Bibliography
Bibliography
[1] Lisa Anthony and Jacob O. Wobbrock. A lightweight multistroke recognizer for user interface prototypes. In: Proceedings of Graphics Interface 2010. GI '10. Ottawa, Ontario, Canada: Canadian Information Processing Society, 2010, pp. 245 252.
1839214.1839258.
[2]
Gary R. Bradski. Computer Vision Face Tracking For Use in a Perceptual User
[3]
Paul A. Viola and Michael J. Jones. Rapid Object Detection using a Boosted Cascade of Simple Features. In: CVPR (1). 2001, pp. 511518.
13 | 13