Click here to Skip to main content
15,867,594 members
Articles / Programming Languages / C++
Article

Mouse gestures recognition

Rate me:
Please Sign up or sign in to vote.
4.88/5 (57 votes)
22 Nov 20013 min read 333.8K   12K   193   46
Feedforward multilayer neural network and mouse gesture recognition

Sample Image

Introduction

Recently I installed Opera 5 and was impressed on a Gesture UI. Moreover several weeks ago I noticed a discussion on CodeProject's Lounge about it. To all appearances people want to know about it too :). IMHO, the neural network most suitable for this purpose. As I a little know neural network I tried to implement such feature themselves.

Neural Network

What is Neural Network ? Hm it's not easy to say. A rephrased definition Zurada, J.M.:

"Neural network software is a software which can acquire, store, and utilize experiential knowledge."

I think I can point any person concerned to theory directly to several neural network sites. Here is small list of web resources about Neural networks:

Implementation

Let's return to mouse gestures. After some research I have chosen a multilayer perceptron and standard back-propagation algorithm for training. The main problem was in the representation of an input data for neural network. The best result I found was in the transformation of a mouse path into a vector of cosines and sines.

For example:

path   {170:82 172:83 175:85 177:86 ...} 
transformed into 
vector {0.45 0.55 0.45 0.71 ... 0.89 0.83 0.89 0.71 ...}

Recognition algorithm.

  1. record a mouse path
  2. smooth a path to a base points
  3. transform points to angles' vector
  4. compute sines and cosines
  5. pass values (cosines and sines) to network's inputs
  6. apply softmax function on an output network vector
  7. find and verify a winner

Neural network architecture.

  • input layers : 32 sinapses
  • hidded layer : 32 neurons
  • output layer : 29 axons (one for each gesture)
  • fully connected layers
  • transfer function : log-sigmoid
  • incremental training algorithm, standard back-propagation method
  • momentum, variable learning rate (slowly reduced)
  • input noise

Application

Training

Sample Image

Before testing the recognition ability you must train the network (or you can load an file image of trained net). You can customize the parameters of the training process, namely: maximum number of cycles, a momentum value, a learning rate, a minimum value of mean square error (in other words "target error"). The training process will stop after achieving either of the conditions: maximum number of cycles or target error. During the training process you can keep an eye on a error's graph, a current gesture (with noise) and 2D network presentation.

Testing

As soon as you have a trained net, you can test it. Select the patterns (or test all of them), a speed value and a noise level. Besides, you can familiarize oneself with ideal presentation of gestures via setting minimal noise and minimal speed.

Recognition

For recognition of mouse gestures you must press right mouse button during moving a mouse. For example for recognition "left" gesture, press right mouse button and move a mouse to the left. If a neural network can recognize the gesture, then you will see the name, probability and ideal presentation of winner. Because of freeware nature of GestureApp the mouse path must have at least 16 points :(. Sorry I didn't implemented a "stretch a path" feature so far.

Note: the direction is very important.

The network is trained to recognize the gestures but not 2D images. Hence, you can draw the "circle" gesture a thousand different ways, but the only valid way is: press mouse button and move a mouse to the right and down and so on. Once more: it's gesture, not 2D image.

Mouse gestures

Image 4 Image 5 Image 6 Image 7
Image 8 Image 9 Image 10 Image 11
Image 12 Image 13 Image 14 Image 15
Image 16 Image 17 Image 18 Image 19
Image 20 Image 21 Image 22 Image 23
Image 24 Image 25 Image 26 Image 27
Image 28 Image 29 Image 30
Image 31 Image 32

Compatibility

Compatible with Win2k, WinXP, Win98, WinMe. Unfortunately doesn't work on WinNT because of the need for the AlphaBlend API.

Acknowledgement

Special Thanks:
My wife Julia for her nice artwork ;)

And thanks to:
Pedro Pombeiro for Selection slider control

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
I am freelance programmer. About 3 years of experience in C++ and I would rather use ATL, STL, WTL but not MFC Smile | :) . Main backgrounds are Win32 API, COM and Networking. Now I am interested about AI (Neural Network, Fuzzy Logic and GA). Currently based in Vladivostok, Russia.

Comments and Discussions

 
GeneralRe: You may consider a little improvements... Pin
Anonymous25-Sep-02 4:47
Anonymous25-Sep-02 4:47 
GeneralCongratulations!!! Pin
Konstantin Vasserman18-Dec-01 2:25
Konstantin Vasserman18-Dec-01 2:25 
GeneralRe: Congratulations!!! Pin
Konstantin Boukreev18-Dec-01 2:33
Konstantin Boukreev18-Dec-01 2:33 
GeneralRe: Congratulations!!! Pin
Konstantin Vasserman18-Dec-01 2:50
Konstantin Vasserman18-Dec-01 2:50 
GeneralRe: Congratulations!!! Pin
Konstantin Boukreev18-Dec-01 3:10
Konstantin Boukreev18-Dec-01 3:10 
GeneralRe: Congratulations!!! Pin
Konstantin Vasserman18-Dec-01 3:30
Konstantin Vasserman18-Dec-01 3:30 
GeneralRe: Congratulations!!! Pin
Konstantin Boukreev18-Dec-01 3:40
Konstantin Boukreev18-Dec-01 3:40 
GeneralRe: Congratulations!!! Pin
Konstantin Boukreev18-Dec-01 3:17
Konstantin Boukreev18-Dec-01 3:17 
Вот еще статья
http://www.programme.ru/index.phtml?arch/102001/102001_54.htm
GeneralToo good Pin
Robert Cao17-Dec-01 20:19
Robert Cao17-Dec-01 20:19 
Generalporting to Windows NT Pin
17-Dec-01 4:23
suss17-Dec-01 4:23 
GeneralRe: porting to Windows NT Pin
Konstantin Boukreev18-Dec-01 2:38
Konstantin Boukreev18-Dec-01 2:38 
GeneralGestureApp.exe - Unable To Locate ... Pin
Erik26-Nov-01 19:17
Erik26-Nov-01 19:17 
GeneralRe: GestureApp.exe - Unable To Locate ... Pin
Konstantin Boukreev26-Nov-01 19:26
Konstantin Boukreev26-Nov-01 19:26 
GeneralRe: GestureApp.exe - Unable To Locate ... Pin
Erik26-Nov-01 19:33
Erik26-Nov-01 19:33 
GeneralRe: GestureApp.exe - Unable To Locate ... Pin
Konstantin Boukreev26-Nov-01 19:38
Konstantin Boukreev26-Nov-01 19:38 
GeneralAlphaBlend Pin
Tim Smith24-Nov-01 4:29
Tim Smith24-Nov-01 4:29 
GeneralRe: AlphaBlend Pin
Konstantin Boukreev24-Nov-01 16:32
Konstantin Boukreev24-Nov-01 16:32 
GeneralRe: AlphaBlend Pin
Nish Nishant25-Nov-01 5:35
sitebuilderNish Nishant25-Nov-01 5:35 
GeneralRe: AlphaBlend Pin
Christian Graus9-Dec-01 16:53
protectorChristian Graus9-Dec-01 16:53 
GeneralInteresting Article Pin
NormDroid23-Nov-01 23:41
professionalNormDroid23-Nov-01 23:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.