Created
January 18, 2013 20:48
-
-
Save jordanorelli/4568402 to your computer and use it in GitHub Desktop.
translate LEAPMotion frames to OSC messages in Python. requires LEAP SDK and pyOSC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Leap, sys, OSC | |
class Listener(Leap.Listener): | |
def __init__(self): | |
super(Listener, self).__init__() | |
client = OSC.OSCClient() | |
client.connect(('127.0.0.1', 9000)) | |
self.client = client | |
def on_frame(self, controller): | |
frame = controller.frame() | |
for hand in frame.hands: | |
for finger in hand.fingers: | |
self.send_finger(finger) | |
def send_finger(self, finger): | |
msg = OSC.OSCMessage() | |
msg.setAddress("/leap/finger/%d" % finger.id) | |
msg.append(finger.tip_position.x) | |
msg.append(finger.tip_position.y) | |
msg.append(finger.tip_position.z) | |
self.client.send(msg) | |
l, c = Listener(), Leap.Controller() | |
c.add_listener(l) | |
print "Press Enter to quit..." | |
sys.stdin.readline() | |
c.remove_listener(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment