FrameΒΆ

Methods:

class com::leapmotion::leap::Frame

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

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

Access Frame objects through an instance of the Controller class:

if(controller.isConnected()) //controller is a Controller object
{
    Frame frame = controller.frame(); //The latest frame
    Frame previous = controller.frame(1); //The previous frame
}

Implement a Listener subclass to receive a callback event when a new Frame is available.

Since
1.0

Public Functions

float currentFramesPerSecond()

The instantaneous framerate.

The rate at which the Leap Motion software is providing frames of data (in frames per second). The framerate can fluctuate depending on available computing resources, activity within the device field of view, software tracking settings, and other factors.

float instantaneousFrameRate = frame.currentFramesPerSecond();

Return
An estimate of frames per second of the Leap Motion Controller.
Since
1.0

void deserialize(byte[] str)

Decodes a byte string to replace the properties of this Frame.

A Controller object must be instantiated for this function to succeed, but it does not need to be connected. To extract gestures from the deserialized frame, you must enable the appropriate gestures first.

Any existing data in the frame is destroyed. If you have references to child objects (hands, fingers, etc.), these are preserved as long as the references remain in scope.

Controller controller = new Controller(); //An instance must exist
byte[] frameBytes = Files.readAllBytes(Paths.get("frame.data"));

Frame reconstructedFrame = new Frame();
reconstructedFrame.deserialize(frameBytes);

Note: The behavior when calling functions which take another Frame object as a parameter is undefined when either frame has been deserialized. For example, calling gestures(sinceFrame) on a deserialized frame or with a deserialized frame as parameter (or both) does not necessarily return all gestures that occurred between the two frames. Motion functions, like scaleFactor(startFrame), are more likely to return reasonable results, but could return anomalous values in some cases.

Since
2.1.0
Parameters
  • str -

    A byte array containing the bytes of a serialized frame.

boolean equals(Frame arg0)

Compare Frame object equality.

Boolean isFrameEqual = thisFrame.equals(thatFrame);

Two Frame objects are equal if and only if both Frame objects represent the exact same frame of tracking data and both Frame objects are valid.

Since
1.0

Finger finger(int id)

The Finger object with the specified ID in this frame.

Use the Frame::finger() function to retrieve the Finger object 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 Finger object is returned.

Finger fingerOfInterest = frame.finger(fingerID);

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 Finger object representing that physical finger may have a different ID than that representing the finger in an earlier frame.

Return
The Finger object with the matching ID if one exists in this frame; otherwise, an invalid Finger object is returned.
Since
1.0
Parameters
  • id -

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

FingerList fingers()

The list of Finger objects detected in this frame, given in arbitrary order.

The list can be empty if no fingers are detected.

Use PointableList::extended() to remove non-extended fingers from the list.

FingerList fingersInFrame = frame.fingers();

Return
The FingerList containing all Finger objects detected in this frame.
Since
1.0

Frame()

Constructs a Frame object.

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

Frame current = controller.frame();
Frame previous = controller.frame(1);

The only time you should use this constructor is before deserializing serialized frame data. Call Frame::deserialize(string) to recreate a saved Frame.

Since
1.0

Gesture gesture(int id)

The Gesture object with the specified ID in this frame.

Use the Frame::gesture() function to return a Gesture object in this frame using an ID obtained in an earlier frame. The function always returns a Gesture object, but if there was no update for the gesture in this frame, then an invalid Gesture object is returned.

Gesture gestureOfInterest = frame.gesture(gestureID);

All Gesture objects representing the same recognized movement share the same ID.

Return
The Gesture object in the frame with the specified ID if one exists; Otherwise, an Invalid Gesture object.
Since
1.0
Parameters
  • id -

    The ID of an Gesture object from a previous frame.

GestureList gestures()

The gestures recognized or continuing in this frame.

GestureList gesturesInFrame = frame.gestures();

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

Return
GestureList the list of gestures.
Since
1.0

GestureList gestures(Frame sinceFrame)

Returns a GestureList containing all gestures that have occurred since the specified frame.

GestureList gesturesSinceFrame = frame.gestures(lastProcessedFrame);

Return
GestureList The list of the Gesture objects that have occurred since the specified frame.
Since
1.0
Parameters
  • sinceFrame -

    An earlier Frame object. The starting frame must still be in the frame history cache, which has a default length of 60 frames.

Hand hand(int 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.

Hand handOfInterest = frame.hand(handID);

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.

Return
The Hand object with the matching ID if one exists in this frame; otherwise, an invalid Hand object is returned.
Since
1.0
Parameters
  • id -

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

HandList hands()

The list of Hand objects detected in this frame, given in arbitrary order.

The list can be empty if no hands are detected.

HandList handsInFrame = frame.hands();

Return
The HandList containing all Hand objects detected in this frame.
Since
1.0

long id()

A unique ID for this Frame.

Consecutive frames processed by the Leap Motion software have consecutive increasing values. You can use the frame ID to avoid processing the same Frame object twice:

long lastFrameID = 0;

void processFrame(Frame frame )
{
    if( frame.id() == lastFrameID ) return;
    //...
    lastFrameID = frame.id();
}

As well as to make sure that your application processes every frame:

int lastProcessedFrameID = 0;

void nextFrame( Controller controller )
{
    long currentID = controller.frame().id();
    for( int history = 0; history < currentID - lastFrameID; history++)
    {
        processNextFrame( controller.frame(history) );
    }
    lastFrameID = currentID;
}

void processNextFrame(Frame frame )
{
    if( frame.isValid() )
    {
        //...
    }
}

Return
The frame ID.
Since
1.0

ImageList images()

The list of images from the Leap Motion cameras.

Return
An ImageList object containing the camera images analyzed to create this Frame.
Since
2.1

InteractionBox interactionBox()

The current InteractionBox for the frame.

See the InteractionBox class documentation for more details on how this class should be used.

InteractionBox box = frame.interactionBox();

Return
The current InteractionBox object.
Since
1.0

boolean isValid()

Reports whether this Frame instance is valid.

A valid Frame is one generated by the Leap::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 null pointer exception. The invalid Frame mechanism makes it more convenient to track individual data across the frame history. For example, you can invoke:

Finger 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.)

Return
True, if this is a valid Frame object; false otherwise.
Since
1.0

Pointable pointable(int 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.

Pointable pointableOfInterest = frame.pointable(pointableID);

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.

Return
The Pointable object with the matching ID if one exists in this frame; otherwise, an invalid Pointable object is returned.
Since
1.0
Parameters
  • id -

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

PointableList 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.

Use PointableList::extended() to remove non-extended fingers from the list.

PointableList pointablesInFrame = frame.pointables();

Return
The PointableList containing all Pointable objects detected in this frame.
Since
1.0

float rotationAngle(Frame sinceFrame)

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).

float rotationInFrame = frame.rotationAngle(startFrame);

The Leap Motion software 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.

Return
A positive value containing the heuristically determined rotational change between the current frame and that specified in the sinceFrame parameter.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the relative rotation.

float rotationAngle(Frame sinceFrame, Vector axis)

The angle of rotation around the specified 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 -pi and pi radians (-180 and 180 degrees).

float rotationAroundXAxis = frame.rotationAngle(startFrame, Vector.xAxis());

The Leap Motion software 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.

Return
A value containing the heuristically determined rotational change between the current frame and that specified in the sinceFrame parameter around the given axis.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the relative rotation.

  • axis -

    The axis to measure rotation around.

Vector rotationAxis(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.

Vector axisOfRotation = frame.rotationAxis(startFrame);

The Leap Motion software 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.

Return
A normalized direction Vector representing the axis of the heuristically determined rotational change between the current frame and that specified in the sinceFrame parameter.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the relative rotation.

Matrix rotationMatrix(Frame sinceFrame)

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

Matrix rotationTransform = frame.rotationMatrix(startFrame);

The Leap Motion software 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.

Return
A transformation Matrix containing the heuristically determined rotational change between the current frame and that specified in the sinceFrame parameter.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the relative rotation.

float rotationProbability(Frame sinceFrame)

The estimated probability that the overall motion between the current frame and the specified frame is intended to be a rotating motion.

float rotationDominance = frame.rotationProbability(startFrame);

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

Return
A value between 0 and 1 representing the estimated probability that the overall motion between the current frame and the specified frame is intended to be a rotating motion.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the relative rotation.

float scaleFactor(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.

float zoomFactor = frame.scaleFactor(startFrame);

The Leap Motion software 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.

Return
A positive value representing the heuristically determined scaling change ratio between the current frame and that specified in the sinceFrame parameter.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the relative scaling.

float scaleProbability(Frame sinceFrame)

The estimated probability that the overall motion between the current frame and the specified frame is intended to be a scaling motion.

float scaleDominance = frame.scaleProbability(startFrame);

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

Return
A value between 0 and 1 representing the estimated probability that the overall motion between the current frame and the specified frame is intended to be a scaling motion.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the relative scaling.

byte[] serialize()

Encodes this Frame object as a byte string.

byte[] serializedFrame = frame.serialize();
Files.write(Paths.get("frame.data"), serializedFrame);

Return
The byte array encoding the data for this frame.
Since
2.1.0

long timestamp()

The frame capture time in microseconds elapsed since an arbitrary point in time in the past.

Use Controller::now() to calculate the age of the frame.

float framePeriod = frame.timestamp() - controller.frame(1).timestamp();

Return
The timestamp in microseconds.
Since
1.0

Tool tool(int id)

The Tool object with the specified ID in this frame.

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

Tool toolOfInterest = frame.tool(toolID);

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 Tool object representing that tool may have a different ID than that representing the tool in an earlier frame.

Return
The Tool object with the matching ID if one exists in this frame; otherwise, an invalid Tool object is returned.
Since
1.0
Parameters
  • id -

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

ToolList tools()

The list of Tool objects detected in this frame, given in arbitrary order.

The list can be empty if no tools are detected.

ToolList toolsInFrame = frame.tools();

Return
The ToolList containing all Tool objects detected in this frame.
Since
1.0

String toString()

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

Return
A description of the Frame as a string.
Since
1.0

TrackedQuad trackedQuad()

Note: This class is an experimental API for internal use only.

It may be removed without warning.

Returns information about the currently detected quad in the scene.

If no quad is being tracked, then an invalid TrackedQuad is returned.

Since
2.2.6

Vector translation(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.

Vector linearMovement = frame.translation(startFrame);

The Leap Motion software 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.

Return
A Vector representing the heuristically determined change in position of all objects between the current frame and that specified in the sinceFrame parameter.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the relative translation.

float translationProbability(Frame sinceFrame)

The estimated probability that the overall motion between the current frame and the specified frame is intended to be a translating motion.

float translationDominance = frame.translationProbability(startFrame);

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

Return
A value between 0 and 1 representing the estimated probability that the overall motion between the current frame and the specified frame is intended to be a translating motion.
Since
1.0
Parameters
  • sinceFrame -

    The starting frame for computing the translation.

Public Static Functions

Frame invalid()

Returns an invalid Frame object.

You can use the instance returned by this function in comparisons testing whether a given Frame instance is valid or invalid. (You can also use the Frame::isValid() function.)

//Average a finger position for the last 10 frames
int count = 0;
Vector average = new Vector();
Finger fingerToAverage = frame.fingers().get(0);
for( int i = 0; i < 10; i++ )
{
    Finger fingerFromFrame = controller.frame(i).finger(fingerToAverage.id());
    if( fingerFromFrame.isValid() )
    {
        average = average.plus(fingerFromFrame.tipPosition());
        count++;
    }
    average = average.divide(count);
}

Return
The invalid Frame instance.
Since
1.0