I’m working on creating a gesture recognition system, and I saw one simple implementation that isn’t as accurate, but is really easy to implement. The idea is that you have a unit circle with the 8 significant angles (0, 45, 90, 135, 180, etc) and you map those angles to a value of 1-8. So 45 would be 2, 180 would be 5, etc. Then you just use the Levenshtein distance algorithm to find the closest matching gesture. I have a prototype that is “almost” working, but I’m having some trouble getting the math functions to play nicely with my algorithm. Right now, I have a list of points representing segments of a defined size that make up the gesture. I iterate over these points and get the theta value of the segment like so: start = points[i] end = points[i + 1] theta = math.atan2((p2[1] – p1[1]), (p2[0] – p1[0])) theta = ((theta + (math.pi * 2)) % (math.pi * 2)) The math.pi correction is so that I’ll have all positive radian values. Makes it a lot easier to compare them. I also have a list containing the radian equivalent values of [0, 45, 90, 135, 180, 225, 270, 315, 360]. I iterate over the segments and compare the theta value to each of those 8 directions (360 is a redundancy so that I can compare values greater than 315 to 0). I use the index of the direction + 1 to get my mapped value. So if I… [Read full story]

## Leave a Reply