Gesture recognition — Kivy v1.0.1-dev documentation

# Gesture recognition

You can easily use these class to create new gesture, 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 him to database
    gdb = GestureDatabase()
    gdb.add_gesture(g)

    # And for the next gesture, try to find him !
    g2 = Gesture()
    # ...
    gdb.find(g2)

class `kivy.gesture.` `Gesture`(tolerance=None)

  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)

    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)

    Calculates the dot product of the gesture with another gesture

  `get_rigid_rotation`(dstpts)

    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 pick an angle based on the first point of the gesture.

  `get_score`(comparison_gesture, rotation_invariant=True)

    Returns the matching score of the gesture against another gesture

  `normalize`(stroke_samples=32)

    Runs the gesture normalization algorithm and calculates the dot product with self

class `kivy.gesture.` `GestureDatabase`

  Bases: `object`

  Class to handle a gesture database.

  `add_gesture`(gesture)

    Add a new gesture in database

  `find`(gesture, minscore=0.90000000000000002, rotation_invariant=True)

    Find current gesture in database

  `gesture_to_str`(gesture)

    Convert a gesture into a unique string

  `str_to_gesture`(data)

    Convert a unique string to a gesture

class `kivy.gesture.` `GestureStroke`

  Gestures can be made up of multiple strokes

  `add_point`(x, y)

    add_point(x=x_pos, y=y_pos) Adds a point to the stroke

  `center_stroke`(offset_x, offset_y)

    Centers the stroke by offseting the points

  `normalize_stroke`(sample_points=32)

    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 control the resolution of the stroke.

  `points_distance`(point1, point2)

    points_distance(point1=GesturePoint, point2=GesturePoint) Returns the distance between two GesturePoint

  `scale_stroke`(scale_factor)

    scale_stroke(scale_factor=float) Scales the stroke down by scale_factor

  `stroke_length`(point_list=None)

    Finds the length of the stroke. If a point list is given, finds the length of that list.