I am writing the leap motion python code to detect gestures. I found out that its would be easier to track the movement of the palm, rather than trying to find the swipe direction But my problem is, I am trying to assign a variable or print out a line, which will tell me if my palm is moving up or moving down or if its still. below is my code:
class SampleListener(Leap.Listener):
finger_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky']
bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal']
state_names = ['STATE_INVALID', 'STATE_START', 'STATE_UPDATE', 'STATE_END']
leap_flag=0
def on_init(self, controller):
print("Initialized")
def on_connect(self, controller):
print("Connected")
# Enable gestures
controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE);
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);
def on_disconnect(self, controller):
# Note: not dispatched when running in a debugger.
print("Disconnected")
def on_exit(self, controller):
print("Exited")
def leap_hand_type(self,controller,leap_flag):
# Detect Hands
global leap_hands
frame = controller.frame()
for hand in frame.hands:
if leap_flag==0:
palmy_current = hand.palm_position.y
palmy_previous = hand.palm_position.y
else:
palmy_previous = palmy_current
palmy_current = hand.palm_position.y
print("%d, %d"%(palmy_current,palmy_previous))
if palmy_previous >palmy_current:
print("moving up")
leap_flag=leap_flag+1
The idea is that for the first frame, the leap_flag will be 0 and for consequent frame, leap_flag will be >0. This way I can compare the previous and current position of the palm and determine the direction of the movement. Unfortunately this is not happening. I am able to see the previous and current values bu it is not entering the comparison loop. Is there something wrong with my logic and is there a better way to get this done?