Gesture

Attributes:

Constants:

class Leap.Gesture

The Gesture class represents a recognized movement by the user.

The Leap Motion Controller watches the activity within its field of view for certain movement patterns typical of a user gesture or command. For example, a movement from side to side with the hand can indicate a swipe gesture, while a finger poking forward can indicate a screen tap gesture.

When the Leap Motion software recognizes a gesture, it assigns an ID and adds a Gesture object to the frame gesture list. For continuous gestures, which occur over many frames, the Leap Motion software updates the gesture by adding a Gesture object having the same ID and updated properties in each subsequent frame.

Important: Recognition for each type of gesture must be enabled using the Controller.enable_gesture() function; otherwise no gestures are recognized or reported.

controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE)
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE)
controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP)
controller.enable_gesture(Leap.Gesture.TYPE_SCREEN_TAP)

Subclasses of Gesture define the properties for the specific movement patterns recognized by the Leap Motion software.

The Gesture subclasses for include:

Circle and swipe gestures are continuous and these objects can have a state of start, update, and stop.

The screen tap gesture is a discrete gesture. The Leap Motion software only creates a single ScreenTapGesture object for each tap and it always has a stop state.

Get valid Gesture instances from a Frame object. You can get a list of gestures with the Frame.gestures() method. You can get a list of gestures since a specified frame by passing an earlier frame to this method. You can also use the Frame.gesture() method to find a gesture in the current frame using an ID value obtained in a previous frame.

Gesture objects can be invalid. For example, when you get a gesture by ID using Frame.gesture(), and there is no gesture with that ID in the current frame, then gesture() returns an Invalid Gesture object (rather than a null value). Always check object validity in situations where a gesture might be invalid.

if gesture.is_valid:
    print "Valid gesture"

The following keys can be used with the Config class to configure the gesture recognizer:

Key string Value type Default value Units
Gesture.Circle.MinRadius float 5.0 mm
Gesture.Circle.MinArc float 1.5 * pi radians
Gesture.Swipe.MinLength float 150 mm
Gesture.Swipe.MinVelocity float 1000 mm/s
Gesture.KeyTap.MinDownVelocity float 50 mm/s
Gesture.KeyTap.HistorySeconds float 0.1 s
Gesture.KeyTap.MinDistance float 3.0 mm
Gesture.ScreenTap.MinForwardVelocity float 50 mm/s
Gesture.ScreenTap.HistorySeconds float 0.1 s
Gesture.ScreenTap.MinDistance float 5.0 mm
controller.config.set("Gesture.Circle.MinRadius", 10.0)
controller.config.set("Gesture.Circle.MinArc", .5)
controller.config.set("Gesture.Swipe.MinLength", 200.0)
controller.config.set("Gesture.Swipe.MinVelocity", 750)
controller.config.set("Gesture.KeyTap.MinDownVelocity", 40.0)
controller.config.set("Gesture.KeyTap.HistorySeconds", .2)
controller.config.set("Gesture.KeyTap.MinDistance", 1.0)
controller.config.set("Gesture.ScreenTap.MinForwardVelocity", 30.0)
controller.config.set("Gesture.ScreenTap.HistorySeconds", .5)
controller.config.set("Gesture.ScreenTap.MinDistance", 1.0)
controller.config.save()

New in version 1.0.

TYPE_INVALID
Type:int

An invalid type.

New in version 1.0.

TYPE_SWIPE
Type:int

A straight line movement by the hand with fingers extended.

for gesture in frame.gestures():
    if gesture.type is Leap.Gesture.TYPE_SWIPE:
        swipe = Leap.SwipeGesture(gesture)

New in version 1.0.

TYPE_CIRCLE
Type:int

A circular movement by a finger.

for gesture in frame.gestures():
    if gesture.type is Leap.Gesture.TYPE_CIRCLE:
        circle = Leap.CircleGesture(gesture)

New in version 1.0.

TYPE_SCREEN_TAP
Type:int

A forward tapping movement by a finger.

for gesture in frame.gestures():
    if gesture.type is Leap.Gesture.TYPE_SCREEN_TAP:
        screen_tap = Leap.ScreenTapGesture(gesture)

New in version 1.0.

TYPE_KEY_TAP
Type:int

A downward tapping movement by a finger.

for gesture in frame.gestures():
    if gesture.type is Leap.Gesture.TYPE_KEY_TAP:
        key_tap = Leap.KeyTapGesture(gesture)

New in version 1.0.

STATE_INVALID
Type:int

An invalid state

New in version 1.0.

STATE_START
Type:int

The gesture is starting. Just enough has happened to recognize it.

for gesture in frame.gestures():
    if gesture.state is Leap.Gesture.STATE_START:
        #Start tracking a continuous gesture (swipe or circle)

New in version 1.0.

STATE_UPDATE
Type:int

The gesture is in progress. (Note: not all gestures have updates).

for gesture in frame.gestures():
    if gesture.state is Leap.Gesture.STATE_UPDATE:
        #Update an in-progress gesture (swipe or circle)

New in version 1.0.

STATE_STOP
Type:int

The gesture has completed or stopped.

for gesture in frame.gestures():
    if gesture.state is Leap.Gesture.STATE_STOP:
        #End a tracked gesture

New in version 1.0.

invalid
Type:An invalid Gesture object.

You can use the instance returned by this function in comparisons testing whether a given Gesture instance is valid or invalid. (You can also use the is_valid attribute.)

New in version 1.0.

classmethod Gesture([gesture])

Constructs a new copy of an Gesture object.

for gesture in frame.gestures():
    if gesture.type is Leap.Gesture.TYPE_CIRCLE:
        circle = Leap.CircleGesture(gesture)
    elif gesture.type is Leap.Gesture.TYPE_SWIPE:
        swipe = Leap.SwipeGesture(gesture)
    elif gesture.type is Leap.Gesture.TYPE_KEY_TAP:
        key_tap = Leap.KeyTapGesture(gesture)
    elif gesture.type is Leap.Gesture.TYPE_SCREEN_TAP:
        screen_tap = Leap.ScreenTapGesture(gesture)

Arguments

gesture (Gesture) – a Gesture object or one of its subclasses. If no gesture parameter is supplied, an invalid Gesture object is returned.

Get valid instances of the Gesture class, which will be one of the Gesture subclasses, from a Frame object.

New in version 1.0.

type
Type:int

The gesture type.

if gesture.type is Leap.Gesture.TYPE_CIRCLE:
    circle = Leap.CircleGesture(gesture)

New in version 1.0.

state
Type:int

The gesture state.

if gesture.state is Leap.Gesture.STATE_START:
    #Start tracking a continuous gesture (swipe or circle)

Recognized movements occur over time and have a beginning, a middle, and an end. The state attribute reports where in that sequence this Gesture object falls.

New in version 1.0.

id
Type:int

The gesture ID.

id = gesture.id

All Gesture objects belonging to the same recognized movement share the same ID value. Use the ID value with the Frame.gesture() method to find updates related to this Gesture object in subsequent frames.

New in version 1.0.

duration
Type:long

The elapsed duration of the recognized movement up to the frame containing this Gesture object, in microseconds.

microseconds = gesture.duration

The duration reported for the first Gesture in the sequence (with the STATE_START state) will typically be a small positive number since the movement must progress far enough for the Leap Motion software to recognize it as an intentional gesture.

See also: duration_seconds

New in version 1.0.

duration_seconds
Type:float

The elapsed duration in seconds.

seconds = gesture.duration_seconds

See also: duration

New in version 1.0.

frame
Type:Frame

The Frame containing this Gesture instance.

owning_frame = gesture.frame

New in version 1.0.

hands
Type:HandList

The list of hands associated with this Gesture, if any.

gesturing_hands = gesture.hands

If no hands are related to this gesture, the list is empty.

New in version 1.0.

pointables
Type:PointableList

The list of fingers and tools associated with this Gesture, if any.

gesturing_pointables = gesture.pointables

If no Pointable objects are related to this gesture, the list is empty.

New in version 1.0.

is_valid
Type:bool

Reports whether this Gesture instance represents a valid Gesture.

if gesture.is_valid:
    print "Valid gesture"

An invalid Gesture object does not represent a snapshot of a recognized movement. Invalid Gesture objects are returned when a valid object cannot be provided. For example, when you get an gesture by ID using Frame.gesture(), and there is no gesture with that ID in the current frame, then gesture() returns an invalid Gesture object (rather than a null value). Always check object validity in situations where an gesture might be invalid.

New in version 1.0.

eq(a, b)

Compare Gesture object equality.

Two Gestures are equal if they represent the same snapshot of the same recognized movement.

New in version 1.0.

ne(a, b)

Compare Gesture object inequality.

Two Gestures are equal only if they represent the same snapshot of the same recognized movement.

New in version 1.0.