LeapJS API Reference
Class

Leap.Frame

Contents

class Leap.Frame

The Frame class represents a set of hand and finger tracking data detected in a single frame.

The Leap detects hands, fingers and tools within the tracking area, reporting their positions, orientations and motions in frames at the Leap frame rate.

Access Frame objects using the Controller.frame() function.

Constructor Top

  Frame ()

Static Properties & Enumerations Top

Leap.Frame Invalid

Properties Top

Leap.Pointable fingers[]
Leap.Gesture gestures[]
Leap.Hand hands[]
String id
Leap.Pointable pointables[]
Number timestamp
Leap.Pointable tools[]
Boolean valid

Methods Top

String dump ()
Leap.Pointable finger (String id)
Leap.Hand hand (String id)
Leap.Pointable pointable (String id)
Number rotationAngle (Leap.Frame sinceFrame, Leap.Vector axis)
Leap.Vector rotationAxis (Leap.Frame sinceFrame)
Leap.Matrix rotationMatrix (Leap.Frame sinceFrame)
Number scaleFactor (Leap.Frame sinceFrame)
Leap.Pointable tool (String id)
String toString ()
Leap.Vector translation (Leap.Frame sinceFrame)

Constructor details Top

frame.js at line 8
Frame ()

Constructs a Frame object.

Frame instances created with this constructor are invalid. Get valid Frame objects by calling the Controller.frame() function.

Static Properties & Enumerations Detail Top

frame.js at line 427
static public Leap.Frame Invalid

An invalid Frame object.

You can use this invalid Frame in comparisons testing whether a given Frame instance is valid or invalid. (You can also check the Frame.valid property.)

Properties Detail Top

frame.js at line 94
public Leap.Pointable fingers[]

The list of Finger objects detected in this frame, given in arbitrary order. The list can be empty if no fingers are detected.

frame.js at line 132
public Leap.Gesture gestures[]

The list of Gesture objects detected in this frame, given in arbitrary order. The list can be empty if no gestures are detected.

Circle and swipe gestures are updated every frame. Tap gestures only appear in the list for a single frame.

frame.js at line 65
public Leap.Hand hands[]

The list of Hand objects detected in this frame, given in arbitrary order. The list can be empty if no hands are detected.

frame.js at line 50
public String id

A unique ID for this Frame. Consecutive frames processed by the Leap have consecutive increasing values.

frame.js at line 75
public Leap.Pointable pointables[]

The list of Pointable objects (fingers and tools) detected in this frame, given in arbitrary order. The list can be empty if no fingers or tools are detected.

frame.js at line 58
public Number timestamp

The frame capture time in microseconds elapsed since the Leap started.

frame.js at line 85
public Leap.Pointable tools[]

The list of Tool objects detected in this frame, given in arbitrary order. The list can be empty if no tools are detected.

frame.js at line 27
public Boolean valid

Reports whether this Frame instance is valid.

A valid Frame is one generated by the Controller object that contains tracking data for all detected entities. An invalid Frame contains no actual tracking data, but you can call its functions without risk of a undefined object exception. The invalid Frame mechanism makes it more convenient to track individual data across the frame history. For example, you can invoke:

var finger = controller.frame(n).finger(fingerID);

for an arbitrary Frame history value, "n", without first checking whether frame(n) returned a null object. (You should still check that the returned Finger instance is valid.)

Methods Detail Top

frame.js at line 396
public String dump ()

Returns a JSON-formatted string containing the hands, pointables and gestures in this frame.

Return Value

String

A JSON-formatted string.

frame.js at line 197
public Leap.Pointable finger (String id)

The finger with the specified ID in this frame.

Use the Frame finger() function to retrieve the finger from this frame using an ID value obtained from a previous frame. This function always returns a Finger object, but if no finger with the specified ID is present, an invalid Pointable object is returned.

Note that ID values persist across frames, but only until tracking of a particular object is lost. If tracking of a finger is lost and subsequently regained, the new Pointable object representing that physical finger may have a different ID than that representing the finger in an earlier frame.

Parameters

String id

The ID value of a finger from a previous frame.

Return Value

Leap.Pointable

The finger with the matching ID if one exists in this frame; otherwise, an invalid Pointable object is returned.

frame.js at line 222
public Leap.Hand hand (String id)

The Hand object with the specified ID in this frame.

Use the Frame hand() function to retrieve the Hand object from this frame using an ID value obtained from a previous frame. This function always returns a Hand object, but if no hand with the specified ID is present, an invalid Hand object is returned.

Note that ID values persist across frames, but only until tracking of a particular object is lost. If tracking of a hand is lost and subsequently regained, the new Hand object representing that physical hand may have a different ID than that representing the physical hand in an earlier frame.

Parameters

String id

The ID value of a Hand object from a previous frame.

Return Value

Leap.Hand

The Hand object with the matching ID if one exists in this frame; otherwise, an invalid Hand object is returned.

frame.js at line 173
public Leap.Pointable pointable (String id)

The Pointable object with the specified ID in this frame.

Use the Frame pointable() function to retrieve the Pointable object from this frame using an ID value obtained from a previous frame. This function always returns a Pointable object, but if no finger or tool with the specified ID is present, an invalid Pointable object is returned.

Note that ID values persist across frames, but only until tracking of a particular object is lost. If tracking of a finger or tool is lost and subsequently regained, the new Pointable object representing that finger or tool may have a different ID than that representing the finger or tool in an earlier frame.

Parameters

String id

The ID value of a Pointable object from a previous frame.

Return Value

Leap.Pointable

The Pointable object with the matching ID if one exists in this frame; otherwise, an invalid Pointable object is returned.

frame.js at line 245
public Number rotationAngle (Leap.Frame sinceFrame, Leap.Vector axis)

The angle of rotation around the rotation axis derived from the overall rotational motion between the current frame and the specified frame.

The returned angle is expressed in radians measured clockwise around the rotation axis (using the right-hand rule) between the start and end frames. The value is always between 0 and pi radians (0 and 180 degrees).

The Leap derives frame rotation from the relative change in position and orientation of all objects detected in the field of view.

If either this frame or sinceFrame is an invalid Frame object, then the angle of rotation is zero.

Parameters

Leap.Frame sinceFrame

The starting frame for computing the relative rotation.

Leap.Vector axis

The axis to measure rotation around.

(Optional)

Return Value

Number

A positive value containing the heuristically determined rotational change between the current frame and that specified in the sinceFrame parameter.

frame.js at line 281
public Leap.Vector rotationAxis (Leap.Frame sinceFrame)

The axis of rotation derived from the overall rotational motion between the current frame and the specified frame.

The returned direction vector is normalized.

The Leap derives frame rotation from the relative change in position and orientation of all objects detected in the field of view.

If either this frame or sinceFrame is an invalid Frame object, or if no rotation is detected between the two frames, a zero vector is returned.

Parameters

Leap.Frame sinceFrame

The starting frame for computing the relative rotation.

Return Value

Leap.Vector

A normalized direction Vector representing the axis of the heuristically determined rotational change between the current frame and that specified in the sinceFrame parameter.

frame.js at line 308
public Leap.Matrix rotationMatrix (Leap.Frame sinceFrame)

The transform matrix expressing the rotation derived from the overall rotational motion between the current frame and the specified frame.

The Leap derives frame rotation from the relative change in position and orientation of all objects detected in the field of view.

If either this frame or sinceFrame is an invalid Frame object, then this method returns an identity matrix.

Parameters

Leap.Frame sinceFrame

The starting frame for computing the relative rotation.

Return Value

Leap.Matrix

A transformation Matrix containing the heuristically determined rotational change between the current frame and that specified in the sinceFrame parameter.

frame.js at line 333
public Number scaleFactor (Leap.Frame sinceFrame)

The scale factor derived from the overall motion between the current frame and the specified frame.

The scale factor is always positive. A value of 1.0 indicates no scaling took place. Values between 0.0 and 1.0 indicate contraction and values greater than 1.0 indicate expansion.

The Leap derives scaling from the relative inward or outward motion of all objects detected in the field of view (independent of translation and rotation).

If either this frame or sinceFrame is an invalid Frame object, then this method returns 1.0.

Parameters

Leap.Frame sinceFrame

The starting frame for computing the relative scaling.

Return Value

Number

A positive value representing the heuristically determined scaling change ratio between the current frame and that specified in the sinceFrame parameter.

frame.js at line 148
public Leap.Pointable tool (String id)

The tool with the specified ID in this frame.

Use the Frame tool() function to retrieve a tool from this frame using an ID value obtained from a previous frame. This function always returns a Pointable object, but if no tool with the specified ID is present, an invalid Pointable object is returned.

Note that ID values persist across frames, but only until tracking of a particular object is lost. If tracking of a tool is lost and subsequently regained, the new Pointable object representing that tool may have a different ID than that representing the tool in an earlier frame.

Parameters

String id

The ID value of a Tool object from a previous frame.

Return Value

Leap.Pointable

The tool with the matching ID if one exists in this frame; otherwise, an invalid Pointable object is returned.

frame.js at line 382
public String toString ()

A string containing a brief, human readable description of the Frame object.

Return Value

String

A brief description of this frame.

frame.js at line 355
public Leap.Vector translation (Leap.Frame sinceFrame)

The change of position derived from the overall linear motion between the current frame and the specified frame.

The returned translation vector provides the magnitude and direction of the movement in millimeters.

The Leap derives frame translation from the linear motion of all objects detected in the field of view.

If either this frame or sinceFrame is an invalid Frame object, then this method returns a zero vector.

Parameters

Leap.Frame sinceFrame

The starting frame for computing the relative translation.

Return Value

Leap.Vector

A Vector representing the heuristically determined change in position of all objects between the current frame and that specified in the sinceFrame parameter.