def body (frame): global lastWord for hand in frame.hands: handType = "LeftHand" if hand.is_left else "RightHand" wordleft = False wordright = False for gesture in frame.gestures(): if handType == "LeftHand": if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if (swipe.state != Leap.Gesture.STATE_START): print swipe.direction.roll * Leap.RAD_TO_DEG if (swipe.direction.roll * Leap.RAD_TO_DEG <= -100 and swipe.direction.roll * Leap.RAD_TO_DEG >= -180 and abs(swipe.direction.pitch * Leap.RAD_TO_DEG - 90) < 30 ) == True: wordleft = True print "bodyleft" if handType == "RightHand": if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if (swipe.state != Leap.Gesture.STATE_START): if (swipe.direction.roll * Leap.RAD_TO_DEG >= 100 and swipe.direction.roll * Leap.RAD_TO_DEG <= 180) == True: wordright = True print "bodyright" if (wordright and wordleft) == True: print "body" lastWord = "body"
def run(self): self.profile.start() # Initialize offset Counter, Timestep i = 0 TIMESTEP = 0.05 while not self.stopped(): now = time.time() # get the time print i if self.source.isPlaying(): i += 1 * self.source.speed if (self.controller.is_connected ): #controller is a Leap.Controller object # Get frame frame = self.controller.frame() # Print frame info print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" % ( frame.id, frame.timestamp, len( frame.hands), len(frame.fingers), len( frame.tools), len(frame.gestures())) # Pause or play if len(frame.hands) == 2: height = frame.hands[0].palm_position.y + frame.hands[ 1].palm_position.y if self.source.isPlaying( ) and height < 200.0: # If playing and hands are down self.source.stop() elif height > 200.0 and not self.source.isPlaying( ): # If not playing and hands are up self.source.setOffset(i * TIMESTEP) self.source.out() if len(frame.gestures()) > 0 and i > 15: maxSwipe = SwipeGesture(frame.gestures()[0]) for gesture in frame.gestures(): if maxSwipe.speed < SwipeGesture(gesture).speed: maxSwipe = SwipeGesture(gesture) if abs(maxSwipe.direction[0]) > abs(maxSwipe.direction[1]): if maxSwipe.direction[0] > 0: # swipe right self.server.prevTrack() else: self.server.nextTrack() # Step the profile one timestep self.parameters = self.profile.step(frame) elapsed = time.time() - now # how long was it running? time.sleep(TIMESTEP - elapsed) self.profile.source.stop()
def on_frame(self, controller): self.printer.echo(controller) self.pointer.move(controller) self.pointer.click(controller) self.pointer.scroll(controller) frame = controller.frame() for hand in frame.hands: normal = hand.palm_normal # Get gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to( circle.normal) <= Leap.PI / 2: clockwiseness = "clockwise" else: clockwiseness = "counterclockwise" # Calculate the angle swept since the last frame swept_angle = 0 if circle.state != Leap.Gesture.STATE_START: previous_update = CircleGesture( controller.frame(1).gesture(circle.id)) swept_angle = (circle.progress - previous_update.progress) * 2 * Leap.PI if circle.state == Leap.Gesture.STATE_STOP and circle.radius > 15 and circle.radius < 25: # go to right or left tab by ctrl+pgdwn or ctrl+pgup if clockwiseness == "clockwise": self.keyboard.press_key(self.keyboard.control_key) self.keyboard.tap_key(self.keyboard.page_down_key) self.keyboard.release_key(self.keyboard.control_key) elif clockwiseness == "counterclockwise": self.keyboard.press_key(self.keyboard.control_key) self.keyboard.tap_key(self.keyboard.page_up_key) self.keyboard.release_key(self.keyboard.control_key) if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) for hand in frame.hands: normal = hand.palm_normal # go back on swipe right; forward on swipe left mouse_pos = self.mouse.position() palm_roll = normal.roll * Leap.RAD_TO_DEG if gesture.state == Leap.Gesture.STATE_START: if swipe.direction.x > 0.33 \ and palm_roll > 90 - self.settings.tolerance["hand_roll"] \ and palm_roll < 90 + self.settings.tolerance["hand_roll"]: # prevent false positives self.mouse.click(mouse_pos[0], mouse_pos[1], 8) elif swipe.direction.x < -0.33 \ and palm_roll > -90 - self.settings.tolerance["hand_roll"] \ and palm_roll < -90 + self.settings.tolerance["hand_roll"]: # prevent false positives self.mouse.click(mouse_pos[0], mouse_pos[1], 9)
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() # Get gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if gesture.state == 1: #print("start") self.start_x = swipe.position[0] self.end_x = None if gesture.state == 2: #print("end") self.end_x = swipe.position[0] # print " Swipe id: %d, state: %s, position: %s, direction: %s, speed: %f, type: %d" % ( # gesture.id, self.state_names[gesture.state], # swipe.position, swipe.direction, swipe.speed, swipe.type) if self.start_x is not None and self.end_x is not None: print("startx|endx: " + str(self.start_x) + "|" + str(self.end_x)) if self.start_x > self.end_x: print("Swipe to the left") if self.start_x < self.end_x: print("Swipe to the right") self.start_x = None self.end_x = None
def on_frame(self, controller): # Get the most recent frame frame = controller.frame() if not frame.hands.empty: # Handle gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) #print "Swipe id: %d, state: %s, position: %s, direction: %s, speed: %f" % ( # gesture.id, self.state_string(gesture.state), # swipe.position, swipe.direction, swipe.speed) #print "%s - state: %d" % (swipe.direction, swipe.state) #if swipe.direction.angle_to(Vector(-1, 0, 0))*180.0/3.14159265 < 90 and swipe.state == 1: if swipe.direction.x < 0 and swipe.state == 1 and ( frame.timestamp - self.timestamp) > 150000: # if the swipe was directed to the left: generate slide swipe key self.timestamp = frame.timestamp print print 'Swipe (ID %d) position: %s speed: %.1f mm/s' % ( gesture.id, swipe.position, swipe.speed) PressKey(13) ReleaseKey(13)
def on_frame( self, controller ): #Leap motion loop listens for any interaction with Leap Motion device frame = controller.frame() #polls for any user input events iBox = frame.interaction_box if not frame.hands.is_empty: #Checks for hands or pointables over Leap hand = frame.hands[0] # fingers on first hand hand2 = frame.hands[1] # fingers on second hand fingers1 = hand.fingers # list of fingers from first hand fingers2 = hand2.fingers # list of fingers from second hand if not frame.fingers.is_empty: #checks fingers if not fingers1.is_empty: #checks if fingers from first hand are present #print iBox.width , iBox.height screenPosition = iBox.normalize_point( fingers1[0].tip_position) self.directional['x'] = int(screenPosition[0] * horiz) self.directional['y'] = -(vert - int(screenPosition[1] * vert)) #print self.directional['x'],self.directional['y'] for gesture in frame.gestures(): #reads in a swipe gesture if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) #print self.state_string(gesture.state) #print swipe.start_position #print swipe.direction #print swipe.position self.on_cleanup()
def on_frame(self, controller): frame=controller.frame(0) for gesture in frame.gestures(): if gesture.type==Leap.Gesture.TYPE_CIRCLE: circle=CircleGesture(gesture) if circle.pointable.direction.angle_to(circle.normal)<=Leap.PI/2: clockwiseness="clockwise" else: clockwiseness="counter-clockwise" 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) + "progress:" + str(circle.progress)+"Radius:" + str(circle.radius)+"swept Angle:" + str(swept_angle*Leap.RAD_TO_DEG)+" "+clockwiseness if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe=SwipeGesture(gesture) print "Swipe ID:" + str(swipe.id)+"State:" + self.state_names[gesture.state]+"Position:"+str(swipe.position)+"Direction:"+str(swipe.direction)+"speed(mm/s):"+str(swipe.speed) if gesture.type==Leap.Gesture.TYPE_SCREEN_TAP: screentap=ScreenTapGesture(gesture) print "screen Tap ID:" + str(gesture.id) + "State:" + self.state_names[gesture.state] + "Position:" + str(screentap.position) + "Direction:" + str(screentap.direction) if gesture.type==Leap.Gesture.TYPE_KEY_TAP: keytap=KeyTapGesture(gesture) print "Key Tap ID: " + str(gesture.id) + " State: " + self.state_names[gesture.state] + "Position:" + str(keytap.position) + "Direction:" + str(keytap.direction)
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() right_swipe = False left_swipe = False # Get gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: curr_gesture = gesture swipe = SwipeGesture(gesture) d = swipe.direction if curr_gesture.state is Leap.Gesture.STATE_STOP: if d.x > 0: right_swipe = True elif d.x < 0: left_swipe = True if right_swipe: print "right swipe -- display mainpage" send_mqtt_cmd("mainpage") time.sleep(1) elif left_swipe: print "left swipe -- display subpage" send_mqtt_cmd("subpage") time.sleep(1)
def day(frame): global lastWord lefthand = False righthand = False if (frame.hands == 2): lefthand = True righthand = True for hand in frame.hands: if hand.is_left: if (abs(hand.palm_normal.roll * Leap.RAD_TO_DEG) >= 150 and hand.direction.roll * Leap.RAD_TO_DEG >= 60 and hand.direction.roll * Leap.RAD_TO_DEG <= 120) == False: lefthand = False else: # print "LEFT OK" lefthand = True else: for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if (swipe.state != Leap.Gesture.STATE_START): # print str(swipe.direction.yaw * Leap.RAD_TO_DEG) + " " + str(swipe.direction.roll * Leap.RAD_TO_DEG) if (swipe.direction.yaw * Leap.RAD_TO_DEG >= 45 and swipe.direction.yaw * Leap.RAD_TO_DEG <= 135 and swipe.direction.roll * Leap.RAD_TO_DEG >= 90 and swipe.direction.roll * Leap.RAD_TO_DEG <= 180) == False: righthand = False else: # print "RIGHT OK" righthand = True if (lefthand and righthand): print "day " lastWord = "day"
def judges(frame): global lastWord lhand = rhand = False if len(frame.hands) == 2: for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) print str(swipe.direction.pitch * Leap.RAD_TO_DEG) + " " + str( swipe.direction.roll * Leap.RAD_TO_DEG) if abs(abs(swipe.direction.pitch * Leap.RAD_TO_DEG) - 90) <= 20 and abs( abs(swipe.direction.roll * Leap.RAD_TO_DEG) - 180) <= 20: lhand = True print "Left ok !" if abs(swipe.direction.pitch * Leap.RAD_TO_DEG + 90) <= 20 and abs( swipe.direction.roll * Leap.RAD_TO_DEG) <= 20: rhand = True print "Right ok !" if lhand and rhand: lastWord = "judges" print "judges" return True return False
def on_frame(self, controller): frame = controller.frame() for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_CIRCLE: #verifica si puede ser considerado un circulo circle = CircleGesture(gesture) #hace cast a un circulo if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/2: clockwiseness = "clockwise" else: clockwiseness = "counter-clockwise" swept_angle = 0 if circle.state != Leap.Gesture.STATE_START: previous = CircleGesture(controller.frame(1).gesture(circle.id)) #sennala el frame anterior del circulo swept_angle = (circle.progress - previous.progress) * 2 * Leap.PI print "ID: " + str(circle.id) + " Progress: " + str(circle.progress) + " Radius: " + str(circle.radius) + " Swept angle: " + str(swept_angle) + " Clockwiseness: " + clockwiseness if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) print "Swipe ID: " + str(swipe.id) + " State: " + self.state_names[gesture.state] + " Position: " + str(swipe.position) + " Direction: " + str(swipe.direction) + " Speed (m/s): " + str(swipe.speed) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screenTap = ScreenTapGesture(gesture) print "Screen Tap ID: " + str(screenTap.id) + " State: " + self.state_names[gesture.state] + " Position: " + str(screenTap.position) + " Direction: " + str(screenTap.direction) if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keyTap = KeyTapGesture(gesture) print "Key Tap ID: " + str(keyTap.id) + " State: " + self.state_names[gesture.state] + " Position: " + str(keyTap.position) + " Direction: " + str(keyTap.direction)
def on_frame(self, controller): frame = controller.frame() pointables = frame.fingers.extended() if len(pointables) == 1: location = pointables.frontmost.stabilized_tip_position iBox = frame.interaction_box normalizedLocation = iBox.normalize_point(location, False) x = normalizedLocation.x * 1920 y = (1 - normalizedLocation.z) * 1080 cursor_update((x, y)) for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_KEY_TAP: cursor_click((x, y)) elif len(pointables) >= 4: for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if swipe.state == 3: clear()
def on_frame(self, controller): # Frame available frame = controller.frame() global cl global councl global bck global fwd # Get gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to( circle.normal) <= Leap.PI / 2: clockwiseness = "clockwise" else: clockwiseness = "counterclockwise" if clockwiseness == "clockwise": cl = (cl + 1) if cl == 35: pubnub.publish('test', 'Turn Right', callback=callback, error=callback) cl = 0 else: councl = councl + 1 if councl == 35: pubnub.publish('test', 'Turn Left', callback=callback, error=callback) councl = 0 if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) swdir = swipe.direction if (swdir.z > 0 and math.fabs(swdir.z) > math.fabs(swdir.y) and math.fabs(swdir.z) > math.fabs(swdir.x)): bck = (bck + 1) print "Move Backward" if bck == 25: pubnub.publish('test', 'Move Backward', callback=callback, error=callback) bck = 0 elif (swdir.z < 0 and math.fabs(swdir.z) > math.fabs(swdir.y) and math.fabs(swdir.z) > math.fabs(swdir.x)): fwd = (fwd + 1) print "Move Forward" if fwd == 25: pubnub.publish('test', 'Move Forward', callback=callback, error=callback) fwd = 0
def on_frame(self, controller): frame = controller.frame() for gesture in frame.gestures(): if gesture.type == Gesture.TYPE_SWIPE and gesture.state in [ 1, 3 ]: # States 1 and 3 are START and STOP, we omit updates with self.swipe_lock: self.swipe[0] = SwipeGesture(gesture)
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() #print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" % ( # frame.id, frame.timestamp, len(frame.hands), len(frame.fingers), len(frame.tools), len(frame.gestures())) # Get hands for hand in frame.hands: handType = "Left hand" if hand.is_left else "Right hand" print handType # Get gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to( circle.normal) <= Leap.PI / 2: clockwiseness = "clockwise" else: clockwiseness = "counterclockwise" # Calculate the angle swept since the last frame swept_angle = 0 if circle.state != Leap.Gesture.STATE_START: previous_update = CircleGesture( controller.frame(1).gesture(circle.id)) swept_angle = (circle.progress - previous_update.progress) * 2 * Leap.PI print " Circle id: %d, %s, progress: %f, radius: %f, angle: %f degrees, %s" % ( gesture.id, self.state_names[gesture.state], circle.progress, circle.radius, swept_angle * Leap.RAD_TO_DEG, clockwiseness) if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) print " Swipe id: %d, state: %s, position: %s, direction: %s, speed: %f" % ( gesture.id, self.state_names[gesture.state], swipe.position, swipe.direction, swipe.speed) if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keytap = KeyTapGesture(gesture) print " Key Tap id: %d, %s, position: %s, direction: %s" % ( gesture.id, self.state_names[gesture.state], keytap.position, keytap.direction) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture) print " Screen Tap id: %d, %s, position: %s, direction: %s" % ( gesture.id, self.state_names[gesture.state], screentap.position, screentap.direction) if not (frame.hands.is_empty and frame.gestures().is_empty): print ""
def detect_swipe(self, controller, gesture): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) open_fingers = self.open_fingers() if not len(open_fingers) == 1 or open_fingers[0] != 1: return None if swipe.direction[0] > 0: return self.action_handler.TURN_ON else: return self.action_handler.TURN_OFF return None
def thankyou(frame): global lastWord for hand in frame.hands: if hand.is_right: for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if swipe.state != Leap.Gesture.STATE_START: if swipe.direction.pitch * Leap.RAD_TO_DEG <= 0 and swipe.direction.pitch * Leap.RAD_TO_DEG >= -120 and abs(swipe.direction.yaw * Leap.RAD_TO_DEG) <= 20: if abs(hand.palm_normal.roll * Leap.RAD_TO_DEG) <= 180 and abs(hand.palm_normal.roll * Leap.RAD_TO_DEG) >= 130: print "Thank You"
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() global vehicle_is_flying #s = json.dumps(frame, default = obj_to_dict) #clientMQTT.publish(topic_leap,s) #print vars(frame.hands) # check just one hand # print(frame.pointables) # for point in frame.pointables: # po = point # print(po.positions) if (len(frame.hands) == 1): if (vehicle_is_flying and vehicle.mode.name == "GUIDED"): for hand in frame.hands: direction = hand.direction #print(direction) normal = hand.palm_normal pitch = direction.pitch * Leap.RAD_TO_DEG roll = normal.roll * Leap.RAD_TO_DEG yaw = direction.yaw * Leap.RAD_TO_DEG * 0.9 ypr = (yaw, pitch, roll) print(ypr) analyzeDirection(ypr) print(hand.grab_strength) print("------") #print ("Pitch : " + str(pitch) + " - Roll : " + str(roll) + " - Yaw : " + str(yaw) ) #print(hand.grab_strength) if (hand.grab_strength >= 1.0): print("Landing...") vehicle.mode = VehicleMode("RTL") sleep(1) else: for gesture in frame.gestures(): #print(gesture) if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) swipeDir = swipe.direction if (swipeDir.y > 0 and math.fabs(swipeDir.x) < math.fabs(swipeDir.y)): print("Take off ", str(swipeDir.y)) global max_altitude arm_and_takeoff(max_altitude)
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() # Get gestures for gesture in frame.gestures(): g = "" if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to( circle.normal) <= Leap.PI / 2: clockwiseness = "clockwise" else: clockwiseness = "counterclockwise" # Calculate the angle swept since the last frame swept_angle = 0 if circle.state != Leap.Gesture.STATE_START: previous_update = CircleGesture( controller.frame(1).gesture(circle.id)) swept_angle = (circle.progress - previous_update.progress) * 2 * Leap.PI g = b"Circle id: %d, %s, progress: %f, radius: %f, angle: %f degrees, %s" % ( gesture.id, self.state_names[gesture.state], circle.progress, circle.radius, swept_angle * Leap.RAD_TO_DEG, clockwiseness) if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) g = b"Swipe id: %d, state: %s, position: %s, direction: %s, speed: %f" % ( gesture.id, self.state_names[gesture.state], swipe.position, swipe.direction, swipe.speed) if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keytap = KeyTapGesture(gesture) g = b"Key Tap id: %d, %s, position: %s, direction: %s" % ( gesture.id, self.state_names[gesture.state], keytap.position, keytap.direction) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture) g = b"Screen Tap id: %d, %s, position: %s, direction: %s" % ( gesture.id, self.state_names[gesture.state], screentap.position, screentap.direction) if g: print g self.client_socket.sendall(g)
def on_frame(self, controller): frame = controller.frame() for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if swipe.direction[0] < 0: print "L", datetime.utcnow().strftime("%H:%M:%S.%f")[:-3] self.socket.send("L") else: print "R", datetime.utcnow().strftime("%H:%M:%S.%f")[:-3] self.socket.send("R") time.sleep(1) return
def is_switching_desktop(self, latest_frame): """ Determines whether a desktop switch must be induced or not. """ for gesture in latest_frame.gestures(): if gesture.type == Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if swipe.state >= 3: if swipe.direction[0] >= 0.8: return 'right' elif swipe.direction[0] <= -0.8: return 'left' return False
def return_gestures(self): controller = self.controller frame = controller.frame() gests.fill(0) for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) gests[0] = 1 # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/2: gests[1] = 1 # clockwise or counterclockwise # Calculate the angle swept since the last frame swept_angle = 0 if circle.state != Leap.Gesture.STATE_START: previous_update = CircleGesture(controller.frame(1).gesture(circle.id)) gests[2] = (circle.progress - previous_update.progress) * 2 * Leap.PI gests[3] = circle.progress gests[4] = circle.radius if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) gests[5] = swipe.position.x gests[6] = swipe.position.y gests[7] = swipe.position.z gests[8] = swipe.direction.x gests[9] = swipe.direction.y gests[10] = swipe.direction.z if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keytap = KeyTapGesture(gesture) gests[11] = keytap.position.x gests[12] = keytap.position.y gests[13] = keytap.position.z gests[14] = keytap.direction.x gests[15] = keytap.direction.y gests[16] = keytap.direction.z if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture) gests[17] = screentap.position.x gests[18] = screentap.position.y gests[19] = screentap.position.z gests[20] = screentap.direction.x gests[21] = screentap.direction.y gests[22] = screentap.direction.z return gests
def on_frame(self, controller): frame = controller.frame() #print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" % ( # frame.id, frame.timestamp, len(frame.hands), len(frame.fingers), len(frame.tools), len(frame.gestures())) if (len(frame.gestures()) > 0 and time.time() - GestureListener.last_gesture_time_ > 1): print "Number of Gestures: %d. last_gesture_time_: %d time: %d" % ( len(frame.gestures()), GestureListener.last_gesture_time_, time.time()) gesture = frame.gestures()[0] if (gesture.type == Leap.Gesture.TYPE_CIRCLE): circle = CircleGesture(gesture) # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to( circle.normal) <= Leap.PI / 4: clockwiseness = "cw" else: clockwiseness = "ccw" # Calculate the angle swept since the last frame swept_angle = 0 if circle.state != Leap.Gesture.STATE_START: previous_update = CircleGesture( controller.frame(1).gesture(circle.id)) swept_angle = (circle.progress - previous_update.progress) * 2 * Leap.PI rospy.loginfo( "Circle id: %d, %s, progress: %f, radius: %f, angle: %f degrees, %s" % (gesture.id, self.state_string( gesture.state), circle.progress, circle.radius, swept_angle * Leap.RAD_TO_DEG, clockwiseness)) if (circle.progress > 1.2): # and circle.state == Leap.Gesture.STATE_STOP): GestureListener.last_gesture_time_ = time.time() HandleCircleGesture(clockwiseness) if (gesture.type == Leap.Gesture.TYPE_SWIPE): swipe = SwipeGesture(gesture) rospy.loginfo( "Swipe id: %d, position: %s, direction: %s, speed: %f, num_fingers: %s, classification: %s" % (gesture.id, swipe.position, swipe.direction, swipe.speed, swipe.pointable, self.classify_swipe(swipe))) if (self.classify_swipe(swipe) != "unknown"): GestureListener.last_gesture_time_ = time.time() HandleSwipeGesture(self.classify_swipe(swipe))
def on_frame(self,controller): frame=controller.frame() for gesture in frame.gestures(): if gesture.type==Leap.Gesture.TYPE_SWIPE: swipe=SwipeGesture(gesture) swipeDir=swipe.direction if(swipeDir.x>0 and math.fabs(swipeDir.x)>math.fabs(swipeDir.y)): print "swiped right" elif(swipeDir.x<0 and math.fabs(swipeDir.x)>math.fabs(swipeDir.y)): print "swiped left" elif(swipeDir.y>0 and math.fabs(swipeDir.x)<math.fabs(swipeDir.y)): print "swiped up" elif(swipeDir.y<0 and math.fabs(swipeDir.x)<math.fabs(swipeDir.y)): print "swiped down"
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if gesture.state == Leap.Gesture.STATE_STOP: print("Swipe id: %d, state: %s, position: %s, direction: %s, speed: %f" % ( gesture.id, self.state_string(gesture.state), swipe.position, swipe.direction, swipe.speed)) if bpy.ops.ed.undo.poll(): bpy.ops.ed.undo() break
def on_frame(self, controller): frame = controller.frame() global numberA global numberB global numberC global numberD tempID = 0 for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) swipeDir = swipe.direction """if (self.state_names[gesture.state] == "STATE_START"): numberA = numberB = numberC = numberD = 0""" if (swipeDir.x > 0 and math.fabs(swipeDir.x) > math.fabs(swipeDir.y)): """print "Swipe right ID: " + str(swipe.id) + " State: " + self.state_names[gesture.state]""" numberA += 1 elif (swipeDir.x < 0 and math.fabs(swipeDir.x) > math.fabs(swipeDir.y)): """print "Swipe left ID: " + str(swipe.id) + " State: " + self.state_names[gesture.state]""" numberB += 1 elif (swipeDir.y > 0 and math.fabs(swipeDir.x) < math.fabs(swipeDir.y)): """print "Swipe up ID: " + str(swipe.id) + " State: " + self.state_names[gesture.state]""" numberC += 1 elif (swipeDir.y < 0 and math.fabs(swipeDir.x) < math.fabs(swipeDir.y)): """print "Swipe down ID: " + str(swipe.id) + " State: " + self.state_names[gesture.state]""" numberD += 1 if (self.state_names[gesture.state] != "STATE_UPDATE"): if (numberA > numberB and numberA > numberC and numberA > numberD): print "SWIPED RIGHT" elif (numberB > numberA and numberB > numberC and numberB > numberD): print "SWIPED LEFT" elif (numberC > numberB and numberC > numberA and numberC > numberD): print "SWIPED UP" elif (numberD > numberB and numberD > numberC and numberD > numberA): print "SWIPED DOWN" numberA = numberB = numberC = numberD = 0
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() if not frame.hands.is_empty: # Get the first hand hand = frame.hands[0] # Check if the hand has any fingers fingers = hand.fingers if not fingers.is_empty: # Calculate the hand's average finger tip position print len(fingers), "- Hello World" # Gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/4: clockwiseness = "clockwise" else: clockwiseness = "counterclockwise" # Calculate the angle swept since the last frame swept_angle = 0 if circle.state != Leap.Gesture.STATE_START: previous_update = CircleGesture(controller.frame(1).gesture(circle.id)) swept_angle = (circle.progress - previous_update.progress) * 2 * Leap.PI print "Circle id" if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) print "Swipe" if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keytap = KeyTapGesture(gesture) print "Key Tap" if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture) print "Screen Tap" if not (frame.hands.is_empty and frame.gestures().is_empty): print ""
def thankyou(frame): global lastWord if lastWord == "thank you": return False if len(frame.hands) == 1: for hand in frame.hands: if hand.is_right: for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if swipe.state != Leap.Gesture.STATE_START: if swipe.direction.pitch * Leap.RAD_TO_DEG <= 0 and swipe.direction.pitch * Leap.RAD_TO_DEG >= -120 and abs(swipe.direction.yaw * Leap.RAD_TO_DEG) <= 20: if abs(hand.palm_normal.roll * Leap.RAD_TO_DEG) <= 180 and abs(hand.palm_normal.roll * Leap.RAD_TO_DEG) >= 130 and lastWord != "thank you": print "thank you" lastWord = "thank you" player('thank_you')
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() # Check for mute if self.muted and len(frame.hands) == 0: self.unmute() for hand in frame.hands: if self.muted and len(hand.fingers.extended()) < 5: self.unmute() break if not self.muted and len(hand.fingers.extended()) == 5: self.mute() break # Get gestures for gesture in frame.gestures(): if gesture.type == Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to( circle.normal) <= L.PI / 2: clockwiseness = "clockwise" else: clockwiseness = "counterclockwise" mod = circle.progress * self.VOL_SPEED if clockwiseness == 'counterclockwise': mod = -mod self.set_volume(self.volume + mod) if gesture.state is Gesture.STATE_STOP: self.save_volume() if gesture.type == Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if gesture.state is Gesture.STATE_STOP: if swipe.direction[0] > 0.6: self.next() elif swipe.direction[0] < -0.6: self.prev() elif abs(swipe.direction[1]) > 0.6: self.pause()
def on_frame(self, controller): frame = controller.frame() #Get Hands for hand in frame.hands: print (hand.palm_position) send_commands(frame) # Get gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) # Determine clock direction using the angle between the pointable and the circle normal if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/2: clockwiseness = "clockwise" else: clockwiseness = "counterclockwise" # Calculate the angle swept since the last frame swept_angle = 0 if circle.state != Leap.Gesture.STATE_START: previous_update = CircleGesture(controller.frame(1).gesture(circle.id)) swept_angle = (circle.progress - previous_update.progress) * 2 * Leap.PI print (" Circle id: %d, %s, progress: %f, radius: %f, angle: %f degrees, %s" % ( gesture.id, self.state_names[gesture.state], circle.progress, circle.radius, swept_angle * Leap.RAD_TO_DEG, clockwiseness)) if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) print (" Swipe id: %d, state: %s, position: %s, direction: %s, speed: %f" % ( gesture.id, self.state_names[gesture.state], swipe.position, swipe.direction, swipe.speed)) if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keytap = KeyTapGesture(gesture) print (" Key Tap id: %d, %s, position: %s, direction: %s" % ( gesture.id, self.state_names[gesture.state], keytap.position, keytap.direction )) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture) print (" Screen Tap id: %d, %s, position: %s, direction: %s" % ( gesture.id, self.state_names[gesture.state], screentap.position, screentap.direction ))