6

I am developing simple mobile app for iPhone and Android platform and I am looking for algorithms that would allow me to trigger certain events (functions) when we detect a certain gesture using internal accelerometer. I work with Phonegap that utilizes HTML5 and javascript which reads three coordinates (x,y and z) from accelerometer on pre-set interval (e.g. every 0.04 sec.).

I wrote a simple function that detects a shaking motion and it works quite fine but it is primitive (it only detects shaking, not the direction) - and I want to detect some other gestures such as: - tilt (to the left/right) - shake up/down - shake left/right - circular motion - turn upside down - etc....

Does anybody have algorithms (or at least mathematical formulas/functions) that can calculate (detect) this kind of gestures based on input values I have (x,y,z and time interval for each call)?

I am looking for any code in any programming language (I will rewrite it to javascript myself. Thanks in advance!

j99
  • 285
  • 2
  • 17
  • I know this question is old but you might want to take a look at GRT (gesture recognition toolkit) from the MIT lab: https://github.com/nickgillian/grt – teh.fonsi May 12 '17 at 16:26

3 Answers3

4

Dynamic Time Warping (DTW) does a good job, however I would recommend using Fast Dynamic Time Warping (Fast DTW). Especially for mobile scenarios, FastDTW is really applicable! For a detailed version, take a look at this research paper: http://cs.fit.edu/~pkc/papers/tdm04.pdf

Edit: Some time ago, I wrote my thesis about 3D gestures for controlling devices in a smart-home setting. See it in action here (there is a link to the PDF, too). I used FastDTW for recognizing gestures on an iPhone.

tilo
  • 14,009
  • 6
  • 68
  • 85
  • Do you know where I could find a working example of fast DTW in action? I googled it but can't seem to find any example - especially not for 3D data (x,y,z) in conjunction with time.. – j99 Feb 01 '12 at 08:32
  • @tilo If you check the link I gave, you will see that I linked this paper. – Ali Feb 01 '12 at 08:35
  • @j99 If you check the link I gave, you will see that I linked this paper too. – Ali Feb 01 '12 at 08:35
  • @Ali just saw that your link points to another question on SO, sorry. Having it here again for reference should be ok. – tilo Feb 01 '12 at 09:07
  • @tilo Hi, thank you for the great answer. Would you mind chatting in regards this issue with me? – Ondrej Tokar Oct 21 '15 at 10:20
1

You might want to try dynamic time warping. An illustrative example is here.

Community
  • 1
  • 1
Ali
  • 56,466
  • 29
  • 168
  • 265
  • 1
    I checked your example - this explains only how to compare two 1D arrays but in our case we have a 3D array (x,y,z) as well as time. If user makes a slow "circular" gesture it should be detected the same if he makes it 2 or 3 times faster... – j99 Feb 01 '12 at 08:27
  • @j99 I said the example is illustrative. If you read the linked papers, you will see that you can extend DTW to 3D arrays, no problem. The speed with which the gesture is made should not cause any problems, warping will take care of that. – – Ali Feb 01 '12 at 08:51
  • @Ali would it be possible we had a private chat? I would like to ask you some things, possibly in exchange for smth. Thanks a lot. – Ondrej Tokar Oct 21 '15 at 11:04
  • @OndrejTokar Please give me your e-mail address. – Ali Oct 21 '15 at 15:16
  • @Ali Here you go: zatokar@gmail.com – Ondrej Tokar Oct 21 '15 at 15:34
  • @OndrejTokar I dropped you an e-mail a minute ago. Please let me know if it did not arrive. – Ali Oct 21 '15 at 16:08
0

If I may be so bold, Fast DTW (and the related, but different FTW of Sakurai and Faloutsos) are not good solutions.

If you constrain the warping (a):

  1. Then using a lower bound DTW is as fast as euclidean distance [b][c]
  2. The accuracy will improve.(a,b)

For constrained warping FTW and Fast DTW are slower than brute force due to overhead (Ira Assent among others have shown this).

a) Ratanamahatana, C. A. and Keogh. E. (2004). Everything you know about Dynamic Time Warping is Wrong

b) Xiaoyue Wang, Hui Ding, Goce Trajcevski, Peter Scheuermann, Eamonn J. Keogh: Experimental Comparison of Representation Methods and Distance Measures for Time Series Data CoRR abs/1012.2789: (2010)

c) http://www.cs.ucr.edu/~eamonn/LB_Keogh.htm

musefan
  • 47,875
  • 21
  • 135
  • 185