Table Of Contents
Gesture recognition¶
This class allows you to easily create new gestures and compare them:
from kivy.gesture import Gesture, GestureDatabase
# Create a gesture
g = Gesture()
g.add_stroke(point_list=[(1,1), (3,4), (2,1)])
g.normalize()
# Add it to the database
gdb = GestureDatabase()
gdb.add_gesture(g)
# And for the next gesture, try to find it!
g2 = Gesture()
# ...
gdb.find(g2)
Warning
You don’t really want to do this: it’s more of an example of how to construct gestures dynamically. Typically, you would need a lot more points, so it’s better to record gestures in a file and reload them to compare later. Look in the examples/gestures directory for an example of how to do that.
- class kivy.gesture.Gesture(tolerance=None)[source]¶
Bases:
builtins.object
A python implementation of a gesture recognition algorithm by Oleg Dopertchouk: http://www.gamedev.net/reference/articles/article2039.asp
Implemented by Jeiel Aranal (chemikhazi@gmail.com), released into the public domain.
- add_stroke(point_list=None)[source]¶
Adds a stroke to the gesture and returns the Stroke instance. Optional point_list argument is a list of the mouse points for the stroke.
- dot_product(comparison_gesture)[source]¶
Calculates the dot product of the gesture with another gesture.
- get_rigid_rotation(dstpts)[source]¶
Extract the rotation to apply to a group of points to minimize the distance to a second group of points. The two groups of points are assumed to be centered. This is a simple version that just picks an angle based on the first point of the gesture.
- class kivy.gesture.GestureDatabase[source]¶
Bases:
builtins.object
Class to handle a gesture database.
- class kivy.gesture.GestureStroke[source]¶
Bases:
builtins.object
Gestures can be made up of multiple strokes.
- normalize_stroke(sample_points=32)[source]¶
Normalizes strokes so that every stroke has a standard number of points. Returns True if stroke is normalized, False if it can’t be normalized. sample_points controls the resolution of the stroke.