Last active
October 21, 2015 16:28
-
-
Save rickybassom/0c596ed31d4774b842ed to your computer and use it in GitHub Desktop.
Leap Motion (Python)
This file contains 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 | |
class LeapMotionListener(Leap.Listener): | |
finger_names = ["Thumb", "Index", "Middle", "Ring", "Pinky"] | |
bone_name = ["Metacarpal", "Proximal", "Intermediate", "Distal"] | |
state_names = ["STATE_INVALID", "STATE_START", "STATE_UPDATE", "STATE_END"] | |
def on_init(self, controller): | |
print("Int") | |
def on_connect(self, controller): | |
print("Motion enabled") | |
controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE) | |
controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP) | |
controller.enable_gesture(Leap.Gesture.TYPE_SCREEN_TAP) | |
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE) | |
def on_disconnect(self, controller): | |
print("Motion dis") | |
def on_exit(self, controller): | |
print("Exited") | |
def on_frame(self, controller): | |
frame = controller.frame() | |
for hand in frame.hands: | |
hand3 = "Left hand" if hand.is_left else "Right hand" | |
hand1 = hand.palm_position[1] | |
hand2 = hand.palm_position[0] | |
print(str(hand1) + " " + str(hand2) + " " + str(hand3)) | |
def Lmain(): | |
listener = LeapMotionListener() | |
controller = Leap.Controller() | |
controller.add_listener(listener) | |
print("Press Enter to quit") | |
try: | |
sys.stdin.readline() | |
except KeyboardInterrupt: | |
pass | |
finally: | |
controller.remove_listener(listener) | |
if __name__ == "__main__": | |
Lmain() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment