The Leap Motion service/daemon provides a WebSocket server listening to port
6347 on the localhost domain. The server provides tracking data in the form of
JSON formated messages (i.e., time-stamped “frames” containing the tracking data at a given moment).
This gist demonstrates how to connect to the device’s websocket stream. It pipes a user specified number offrames from the Leap’s websocket stream to stdout or to a user specified filename.
See Protocol for communicating with leapd for more info and updates.
The websocket stream emits JSON-formatted data frames. (See an example.) The attributes of a frame in the JSON message are similar, but not identical to those of a Frame object obtained through the javascript API:
id: float
r: array of floats (Matrix)
s: float
t: array of floats (Vector)
timestamp: integer
hands: array of Hand objects
direction: array of floats (Vector)
id: integer
palmNormal: array of floats (Vector)
palmPosition: array of floats (Vector)
palmVelocity: array of floats (Vector)
r: array of floats (Matrix)
s: float
sphereCenter: array of floats (Vector)
sphereRadius: float
t: array of floats (Vector)
interactionBox: object
center: array of floats (Vector)
size: array of floats (Vector)
pointables: array of Pointable objects
direction: array of floats (Vector)
handId: integer
id: integer
length: float
stabilizedTipPosition: array of floats (Vector)
tipPosition: array of floats (Vector)
tipVelocity: array of floats (Vector)
tool: boolean (true or false)
touchDistance: float
touchZone: string - one of none, hovering, touching
gestures: array of Gesture objects
center: array of floats (Vector)
duration: integer microseconds
handIds: array of integers
id: integer
normal: array of floats
pointableIds: array
progress: float,
radius: float,
state: string - one of start, update, stop
type: string - one of circle, swipe, keyTap, screenTap
The motion deltas (r, s, t) attached to Hand and Frame objects are snapshots of the motion changes occuring across frames. These deltas must be combined with those of a previous frame to derive the relative motion.
r is a 3x3 rotation matrixs is a scale factort is a 3-element translation vectorrrotation delta
The matrix expressing the relative rotation between two frames can be calculated by multiplying the r matrix from the current frame by the inverse of the r matrix of the starting frame.
sscale factor
The relative scaling factor between two frames can be calculated by subtracting the s value from the starting frame from the current s value and taking the natural logarithm of the result.
ttranslation delta
The relative translation between two frames can be calculated by subtracting the t vector from the starting frame from the current t factor.
