I am new to leap motion. But on the last couple of days i was able to detect swipe gestures differentiating between up,down,left and right also the rotational gestures clock and anti clock wise.Yet when i tried to combine the two gestures in an if condition sometime the leap motion gets confused whether its a swipe or a circle as it takes big effort to swipe without doing a semi-circle so i was asking if there is certain extra parametre that i should take in consideration in my condition
thats my code in python 2.7
import Leap, sys, thread, time , math
from Leap import CircleGesture, SwipeGesture
class LeapMotionListener(Leap.Listener):
finger_names = ['thump','index','middle','ring','pinky']
bone_names = ['metacarpal','proximal','intermediate','distal']
state_names = ['STATE_INVALID','STATE_START','STATE_UPDATE','STATE_END']
def on_init(self,controller):
print "Initialized"
def on_connect(self,controller):
print "leap Motion Connected"
controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE);
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);
def on_disconnect(self,controller):
print "leap Motion Disconnected"
def on_exit(self,controller):
print "EXIT"
def on_frame(self,controller):
frame=controller.frame()
for gesture in frame.gestures():
if gesture.type == Leap.Gesture.TYPE_SWIPE:
swipe = SwipeGesture(gesture)
swipeDirection = swipe.direction
if (swipeDirection.x > 0 and math.fabs(swipeDirection.x) > math.fabs(swipeDirection.y)):
print"Swipe Right"
elif (swipeDirection.x < 0 and math.fabs(swipeDirection.x) > math.fabs(swipeDirection.y)):
print"Swipe Left"
elif (swipeDirection.y > 0 and math.fabs(swipeDirection.x) < math.fabs(swipeDirection.y)):
print"Swipe Up"
elif (swipeDirection.y < 0 and math.fabs(swipeDirection.x) < math.fabs(swipeDirection.y)):
print"Swipe Down"
print"=================================="
elif gesture.type == Leap.Gesture.TYPE_CIRCLE:
circle = CircleGesture(gesture)
if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/2:
clockwiseness = "clock wise"
else:
clockwiseness = "anti-clock wise"
swept_angle = 0
if circle.state != Leap.Gesture.STATE_START:
previous = CircleGesture(controller.frame(1).gesture(circle.id))
swept_angle = (circle.progress - previous.progress) * 2 * Leap.PI
print "ID: " + str(circle.id)
print "progress: " + str(circle.progress)
print "radius: " + str(circle.radius)
print "swept angle " + str(swept_angle * Leap.RAD_TO_DEG)
print " " + clockwiseness
print"=================================="
def main():
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":
main()