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(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() #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 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 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): # 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 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 ))
def on_frame(self, controller): frame = controller.frame() for gesture in frame.gestures(): """ if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) logging.debug("rotate") board.rotate_shape(rotate()) print "Rotate" """ #if gesture.type == Leap.Gesture.TYPE_KEY_TAP: # keytap = KeyTapGesture(gesture) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture) game.toggle_pause() print "pause" elif 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)): logging.debug("Swiped Right") board.move_right() print "Right" elif (swipeDir.x < 0 and math.fabs(swipeDir.x) > math.fabs(swipeDir.y)): logging.debug("Swiped Left") board.move_left() print "Left" elif (swipeDir.y < 0 and math.fabs(swipeDir.x) < math.fabs(swipeDir.y)): logging.debug("Swiped Down") board.move_down() print "Swiped down"
def deal(self, frame, pre): frameEach = {} handData = [] for hand in frame.hands: handEach = { "handType": "Left hand" if hand.is_left else "Right hand" } position = str(hand.palm_position)[1:-1].split(',') pos = [float(p) for p in position] direction = str(hand.direction)[1:-1].split(',') dirs = [float(p) for p in direction] handEach["palmPosition"] = pos # handEach["palm_normal"] = str(hand.palm_normal) handEach["direction"] = dirs handEach["handerId"] = hand.id fingerData = [] for finger in hand.pointables: fingerEach = {} fingerEach['fingerId'] = finger.id fingerEach['fingerName'] = self.finger_names[finger.id % 10] position = str(finger.direction)[1:-1].split(',') pos = [float(p) for p in position] direction = str(finger.tip_position)[1:-1].split(',') dirs = [float(p) for p in direction] fingerEach['direction'] = pos fingerEach['tipPostion'] = dirs fingerData.append(fingerEach) handEach['finger'] = fingerData for finger in hand.pointables: position = float(str(finger.direction)[1:-1].split(',')[1]) if position < -0.5: gestureData = {} gestureData["type"] = 'keytap' gestureData["pointableId"] = finger.id handData.append(handEach) frameEach["hand"] = handData frameEach['gesture'] = [gestureData] return frameEach handData.append(handEach) frameEach["hand"] = handData gestureData = [] for gesture in frame.gestures(): gestureEach = {} #Gesture 1 if gesture.type == Leap.Gesture.TYPE_CIRCLE: gestureEach["type"] = 'circle' #Gesture 2 if gesture.type == Leap.Gesture.TYPE_SWIPE: gestureEach["type"] = "swipe" #Gesture 3 if gesture.type == Leap.Gesture.TYPE_KEY_TAP: gestureEach["type"] = "keytap" gestureEach["pointableId"] = int( str(gesture.pointables[0]).split(":")[-1]) keytap = KeyTapGesture(gesture) position = str(keytap.position)[1:-1].split(',') pos = [float(p) for p in position] direction = str(keytap.direction)[1:-1].split(',') dirs = [float(p) for p in direction] gestureEach["state"], gestureEach["position"], gestureEach[ "direction"] = self.state_names[gesture.state], pos, dirs if len(gestureData): gestureData[0] = gestureEach else: gestureData.append(gestureEach) break #Gesture 4 if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: gestureEach["type"] = "screentap" gestureEach["pointableId"] = str( gesture.pointables[0]).split(":")[-1] # print gestureEach['pointableId'] screentap = ScreenTapGesture(gesture) position = str(screentap.position)[1:-1].split(',') pos = [float(p) for p in position] direction = str(screentap.direction)[1:-1].split(',') dirs = [float(p) for p in direction] gestureEach["state"], gestureEach["position"], gestureEach[ "direction"] = self.state_names[gesture.state], pos, dirs if len(gestureData): gestureData[0] = gestureEach else: gestureData.append(gestureEach) break gestureData.append(gestureEach) frameEach["gesture"] = gestureData return frameEach
def on_frame(self, controller): frame = controller.frame() interactionBox = frame.interaction_box self.scale = 1.0 self.kaydirma_miktari = 20 for hand in frame.hands: handType = "Left Hand -> " if hand.is_left else "Right Hand ->" print handType + "\t Hand ID:" + str(hand.id) + "\t x:" + str( hand.palm_position[0]) + "\t y:" + str( hand.palm_position[1]) + "\t z:" + str( hand.palm_position[2]) self.yukari_asagi.append(hand.palm_position[1]) self.saga_sola.append(hand.palm_position[0]) self.pinch = hand.pinch_strength print ">>>>>>>>>>>>>>>>>>>>><<PINCH :" + str( self.pinch) + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" #------------------------------ left right control ------------------------------- if len(self.saga_sola) > 1: if self.saga_sola[0] + 1 < self.saga_sola[1]: self.yon = self.yon + self.kaydirma_miktari self.updateCircle(self.pinch, self.yon, self.yukariasagi) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<pedal saga" self.ser.write("Muslum Turk6") elif self.saga_sola[0] > self.saga_sola[1] + 1: self.yon = self.yon - self.kaydirma_miktari self.updateCircle(self.pinch, self.yon, self.yukariasagi) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<pedal sola" self.ser.write("Muslum Turk4") else: self.updateCircle(self.pinch, self.yon, self.yukariasagi) self.ser.write("Muslum Turk0") self.saga_sola[:] = [] #------------------------------ up down control ------------------------------------- if len(self.yukari_asagi) > 1: if self.yukari_asagi[0] + 1 < self.yukari_asagi[1]: self.yukariasagi = self.yukariasagi - self.kaydirma_miktari self.updateCircle(self.pinch, self.yon, self.yukariasagi) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<pedal yukari" self.ser.write("Muslum Turk8") elif self.yukari_asagi[0] > self.yukari_asagi[1] + 1: self.yukariasagi = self.yukariasagi + self.kaydirma_miktari self.updateCircle(self.pinch, self.yon, self.yukariasagi) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<pedal asagi" self.ser.write("Muslum Turk2") else: self.updateCircle(self.pinch, self.yon, self.yukariasagi) self.ser.write("Muslum Turk0") self.yukari_asagi[:] = [] #--------------------------- gesture contoll ----------------------------- for gesture in frame.gestures(): # ------------------ Circle Detected if gesture.type == Leap.Gesture.TYPE_CIRCLE: circle = CircleGesture(gesture) print "Circle ID :" + str(circle.id) + "\tProgress :" + str( circle.progress) + "\tRadius :" + str(circle.radius) if circle.id > 3: self.ser.write("cirleq") # -------------- Swipe Detected if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) print "Swipe ID :" + str( swipe.id) + "\t State :" + self.state_names[ gesture.state] + "\tPosition :" + str( swipe.position) + "\t Speed (mm/s):" + str( swipe.speed) # --------------- ScreenTap Detected if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture) print "ScreenTap ID :" + str( gesture.id) + "\t State :" + self.state_names[ gesture.state] + "\t Position :" + str( screentap.position) # -------------- KeyTap Detected if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keytap = KeyTapGesture(gesture) print "KeyTap ID :" + str(keytap.id) if keytap.id > 3: self.ser.write("keytapw")
def on_frame(self, controller): #controller.config.set("Gesture.Swipe.MinLength", 25.0) #controller.config.set("Gesture.Swipe.MinVelocity", 10.0) #controller.config.save() # 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 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" print clockwiseness os.system('xdotool key XF86AudioRaiseVolume') time.sleep(0.3) break else: clockwiseness = "counterclockwise" print clockwiseness os.system('xdotool key XF86AudioLowerVolume') time.sleep(0.3) break 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 abs(swipe.direction.x) > abs(swipe.direction.y) and abs( swipe.direction.x) > abs(swipe.direction.z): if len(frame.fingers.extended()) < 3: if swipe.direction.x > 0: print 'right with 1 or 2 finger' os.system('xdotool key Right') time.sleep(1) break else: print 'left with 1 or 2 finger' os.system('xdotool key Left') time.sleep(1) break else: if swipe.direction.x > 0: print 'right with more than 2 finger' os.system('xdotool key super+Right') time.sleep(1) break else: print 'left with more than 2 finger' os.system('xdotool key super+Left') time.sleep(1) break if abs(swipe.direction.y) > abs(swipe.direction.x) and abs( swipe.direction.y) > abs(swipe.direction.z): if len(frame.fingers.extended()) < 3: if swipe.direction.y > 0: print 'up with 1 or 2 finger' os.system('xdotool key Up') time.sleep(2) break else: print 'down with 1 or 2 finger' os.system('xdotool key Down') time.sleep(2) break else: if swipe.direction.y > 0: print 'up with more than 2 finger' os.system('xdotool key super+Up') time.sleep(2) break else: print 'down with more than 2 finger' os.system( "xdotool windowminimize $(xdotool getactivewindow)" ) time.sleep(2) break 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 ) print 'tap' os.system("xdotool key Return") time.sleep(1) break 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 ) print 'tap' os.system("xdotool key Return") time.sleep(1) break
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())) if not frame.hands.empty: # Get the first hand hand = frame.hands[0] # Check if the hand has any fingers fingers = hand.fingers if not fingers.empty: # Calculate the hand's average finger tip position avg_pos = Leap.Vector() for finger in fingers: avg_pos += finger.tip_position avg_pos /= len(fingers) print "Hand has %d fingers, average finger tip position: %s" % ( len(fingers), avg_pos) # Get the hand's sphere radius and palm position print "Hand sphere radius: %f mm, palm position: %s" % ( hand.sphere_radius, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles print "Hand pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG) # code.interact(local = locals()) # 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: %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 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) 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_string( 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_string(gesture.state), screentap.position, screentap.direction) while not frame.hands.empty == True: # code.interact(local = locals()) if hand.direction.pitch > 0.5: print('pump now flooding') arduino.write("U\n") # turns ONE MOTOR ON time.sleep(2) arduino.write('N\n') # turns ALL OFF break elif hand.direction.pitch < -0.2: print('pump now draining') arduino.write('D\n') # turns TWO MOTORS ON time.sleep(2) arduino.write('N\n') # turns ALL OFF break else: print('pumps now off') arduino.write('N\n') # turns ALL OFF break if not (frame.hands.empty and frame.gestures().empty): print ""
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'] 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_KEY_TAP); controller.enable_gesture(Leap.Gesture.TYPE_SCREEN_TAP); 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 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 " %s, id %d, position: %s" % ( handType, hand.id, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles print " pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG) # Get arm bone arm = hand.arm print " Arm direction: %s, wrist position: %s, elbow position: %s" % ( arm.direction, arm.wrist_position, arm.elbow_position) test # Get fingers for finger in hand.fingers: print " %s finger, id: %d, length: %fmm, width: %fmm" % ( self.finger_names[finger.type], finger.id, finger.length, finger.width) # Get bones for b in range(0, 4): bone = finger.bone(b) print " Bone: %s, start: %s, end: %s, direction: %s" % ( self.bone_names[bone.type], bone.prev_joint, bone.next_joint, bone.direction) # Get tools for tool in frame.tools: print " Tool id: %d, position: %s, direction: %s" % ( tool.id, tool.tip_position, tool.direction) # 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 on_frame(self, controller): # Get the most recent frame frame = controller.frame() # Get hands hands = frame.hands arms = frame.arm fingers = frame.finger tools = frame.tools # Get gesture as list gestures = list(frame.gestures()) # Get the number of each feature so that we can decide which one to work on numHands = len(hands) numArms = len(arms) numFingers = len(fingers) numTools = len(tools) numGestures = len(gestures) if numHands >= 1: # Get the first hand or we can use a "for hand in hands" and use the same index to specify the arm hand = hands[0] arm = arms[0] # Get the palm position normal = hand.palm_normal direction = hand.direction print( "Hand: position %s, pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % (hand.palm_position, direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG)) print("Arm direction: %s, wrist position: %s, elbow position: %s" % (arm.direction, arm.wrist_position, arm.elbow_position)) # Tools still a wip if numTools >= 1: tool = tools[0] print("Tool position: %s, direction: %s" % (tool.tip_position, tool.direction)) if numGestures >= 1: for gesture in gestures: if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) print( "Swipe state: %s, position: %s, direction: %s, speed: %f" % (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: %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: %s, position: %s, direction: %s" % (self.state_names[gesture.state], screentap.position, screentap.direction))
def on_frame(self, controller): frame = controller.frame() if len(frame.hands) == 0: #si l'utilisateur n'est pas devant la Leap #print "retournez devant la Leap plx" self.sendMSG(-1,["positionMain","distance"]) return else: finger = None hand = frame.hands[0] for i in hand.fingers: if(i.type()==1): finger=i break if finger is None : #si l'index de l'utilisateur n'est pas visible mais qu'il est devant la Leap #print "index non detecte" self.sendMSG(-1,["positionMain","distance"]) self.isInZone = False self.isEnteringZone = False return else: position = finger.tip_position.to_float_array() #vitesse = finger.tip_velocity.to_float_array() #direction = finger.direction.to_float_array() self.sendMSG(self.Vscreen.distanceFromScreen(hand.palm_position),["positionMain","distance"]) # self.sendMSG(distance3d(self.Vscreen.Center,hand.palm_position),["positionMain","distance"]) handFacesScreen = self.Vscreen.isFacingTheScreen(hand.palm_position) fingerFacesScreen = self.Vscreen.isFacingTheScreen(position) if(handFacesScreen^fingerFacesScreen and not self.isTimerRunning): #en train d'entrer dans la zone if( (not self.isEnteringZone) and (not self.isInZone)): self.sendMSG("bang",["positionMain","debutentree"]) # print "debutentree" self.startAsyncTimer() if( (not self.isEnteringZone) and (self.isInZone) ): self.sendMSG("bang",["positionMain","debutsortie"]) print "debutsortie" self.isSwipeComplete = True self.startAsyncTimer() self.isEnteringZone = True self.isInZone = False if(fingerFacesScreen and handFacesScreen and not self.isTimerRunning): #dans la zone if( (not self.isInZone) ): self.sendMSG("bang",["positionMain","entree"]) # print "entree" self.startAsyncTimer() self.isInZone = True self.isEnteringZone = False if( (not fingerFacesScreen) and (not handFacesScreen) and not self.isTimerRunning): #completement hors de la zone if( (self.isEnteringZone) or (self.isInZone) ): self.sendMSG("bang",["positionMain","sortie"]) # print "sortie" self.startAsyncTimer() self.isInZone = False self.isEnteringZone = False # Get gestures for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_CIRCLE and not self.isTimerRunning: 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 = "trigo" else: clockwiseness = "horaire" if circle.state is Leap.Gesture.STATE_START and self.isCircleComplete: print "starting circle "+clockwiseness self.isCircleComplete = False self.sendMSG("bang",["events","circle",clockwiseness,"start"]) if circle.state is Leap.Gesture.STATE_STOP and not self.isCircleComplete: print "stopping circle "+clockwiseness self.isCircleComplete = True self.startAsyncTimer() self.sendMSG("bang",["events","circle",clockwiseness,"stop"]) if gesture.type == Leap.Gesture.TYPE_SWIPE and not self.isTimerRunning: swipe = SwipeGesture(gesture) velocity = distance3d(hand.palm_velocity,[0,0,0]) isHorizontal = abs(swipe.direction[0]) > abs(swipe.direction[1]) if(isHorizontal): if(swipe.direction[0] > 0): swipeDirection = "right" else: swipeDirection = "left" else: if(swipe.direction[1] > 0): swipeDirection = "up"; else: swipeDirection = "down"; if swipe.state is Leap.Gesture.STATE_START and self.isSwipeComplete: self.isSwipeComplete = False print "swipe "+swipeDirection+" occurred" self.sendMSG(velocity,["events","swipe",swipeDirection]) if swipe.state is Leap.Gesture.STATE_UPDATE: if self.isSwipeComplete: self.isSwipeComplete = False # print "swipe speed : %d" % (velocity) if swipe.state is Leap.Gesture.STATE_STOP and not self.isSwipeComplete: print "swipe stopped" self.isSwipeComplete = True self.startAsyncTimer() self.sendMSG("bang",["events","swipe","stop"]) if gesture.type == Leap.Gesture.TYPE_KEY_TAP and not self.isTimerRunning: keytap = KeyTapGesture(gesture) self.startAsyncTimer(); print "keytap occurred" self.sendMSG("bang",["events","keytap"]) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP and not self.isTimerRunning: screentap = ScreenTapGesture(gesture) self.startAsyncTimer(); print "screentap occurred" self.sendMSG("bang",["events","screentap"])
def on_frame(self, controller): global right, left t_pos = [0, 0, 0] t_dir = [0, 0, 0] # 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 " %s, id %d, position: %s" % ( # handType, hand.id, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction if hand.is_left: left[0] = hand.palm_position[0] left[1] = hand.palm_position[1] left[2] = hand.palm_position[2] else: right[0] = hand.palm_position[0] right[1] = hand.palm_position[1] right[2] = hand.palm_position[2] self.socketio.emit( 'input', { "action": "move", "value": { "hand": handType, "direction": [ hand.palm_position[0], hand.palm_position[1], hand.palm_position[2] ] }, "timestamp": frame.timestamp }) # Calculate the hand's pitch, roll, and yaw angles '''print " pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG)''' # Get arm bone arm = hand.arm '''print " Arm direction: %s, wrist position: %s, elbow position: %s" % ( arm.direction, arm.wrist_position, arm.elbow_position)''' # Get fingers for finger in hand.fingers: '''print " %s finger, id: %d, length: %fmm, width: %fmm" % ( self.finger_names[finger.type], finger.id, finger.length, finger.width)''' # Get bones for b in range(0, 4): bone = finger.bone(b) '''print " Bone: %s, start: %s, end: %s, direction: %s" % ( self.bone_names[bone.type], bone.prev_joint, bone.next_joint, bone.direction)''' # Get tools for tool in frame.tools: '''print " Tool id: %d, position: %s, direction: %s" % ( tool.id, tool.tip_position, tool.direction)''' # 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)''' for i in range(0, 3): t_pos[i] = swipe.position[i] for i in range(0, 3): t_dir[i] = swipe.direction[i] self.socketio.emit( 'input', { "action": "swipe", "value": { "speed": swipe.speed, "position": t_pos, "direction": t_dir }, "timestamp": frame.timestamp }) 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) for i in range(0, 3): t_pos[i] = keytap.position[i] for i in range(0, 3): t_dir[i] = keytap.direction[i] self.socketio.emit( 'input', { "action": "keytap", "value": { "position": t_pos, "direction": t_dir }, "timestamp": frame.timestamp }) 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) for i in range(0, 3): t_pos[i] = screentap.position[i] for i in range(0, 3): t_dir[i] = screentap.direction[i] self.socketio.emit( 'input', { "action": "screentap", "value": { "position": t_pos, "direction": t_dir }, "timestamp": frame.timestamp }) if not (frame.hands.is_empty and frame.gestures().is_empty): pass
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() x, y, z = (0, 1, 2) normal = frame.hands[0].palm_normal position = frame.hands[0].stabilized_palm_position print "Normal:", normal[0], normal[1], normal[2] # ParaView Manipulation: move camera so it appears data is being moved by hand camera.SetFocalPoint(-position[x] / 50., -position[y] / 100., -position[z] / 10.) # Render the new camera position # Note that could be rendered after checking for hand to retain position after hand removal Render() print "hands: %d, fingers: %d, tools: %d, gestures: %d" % (len( frame.hands), len(frame.fingers), len( frame.tools), len(frame.gestures())) if not frame.hands.is_empty: # Get the first hand hand = frame.hands[0] # Check if the hand has any fingers # Get the hand's sphere Radius=1 and palm position print "Hand sphere Radius=1: %f mm, palm position: %s" % ( hand.sphere_radius, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles print "Hand pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG) # 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: %d, %s, progress: %f, Radius=1: %f, angle: %f degrees, %s" % ( gesture.id, self.state_string( gesture.state), circle.progress, circleradius, 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_string(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_string( 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_string(gesture.state), screentap.position, screentap.direction) if not (frame.hands.is_empty and frame.gestures().is_empty): print ""
def on_frame(self, controller): frame = controller.frame() #hand = frame.hands[0] # Open Spotify/Close if len(frame.hands) == 2 and (time.time() - self.prevTime) > self.minTime: self.prevTime = time.time() if (math.fabs(frame.hands[0].grab_strength - frame.hands[1].grab_strength) > 0.95): print "Close Spotify" os.system("TASKKILL /F /IM Spotify.exe") else: print "Open Spotify" os.system("start Spotify.lnk") for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) direction = swipe.direction if (direction.x > 0 and math.fabs(direction.x) > math.fabs(direction.y) and (time.time() - self.prevTime) > self.minTime): win32api.keybd_event(VK_MEDIA_NEXT_TRACK, code2) self.prevTime = time.time() print "Next Track, and the speed is %f" % (swipe.speed) #elif gesture.state is Leap.Gesture.STATE_START and direction.x < 0 and math.fabs(direction.x) > math.fabs(direction.y): elif (direction.x < 0 and math.fabs(direction.x) > math.fabs(direction.y) and (time.time() - self.prevTime) > self.minTime): win32api.keybd_event(VK_MEDIA_PREV_TRACK, code3) self.prevTime = time.time() print "Previous Track" #elif gesture.state is Leap.Gesture.STATE_START and direction.y < 0 and math.fabs(direction.y) > math.fabs(direction.x): elif (direction.y < 0 and math.fabs(direction.y) > math.fabs(direction.x)): win32api.keybd_event(VK_VOLUME_DOWN, code5) print "Volume Down" #elif gesture.state is Leap.Gesture.STATE_START and direction.y > 0 and math.fabs(direction.y) > math.fabs(direction.x): elif (direction.y > 0 and math.fabs(direction.y) > math.fabs(direction.x)): win32api.keybd_event(VK_VOLUME_UP, code6) print "Volume Up" elif gesture.type == Leap.Gesture.TYPE_KEY_TAP and ( time.time() - self.prevTime) > self.minTime: tap = KeyTapGesture(gesture) win32api.keybd_event(VK_MEDIA_PLAY_PAUSE, code1) self.prevTime = time.time() print "Play/Pause Track" # Screen tap to mute/unmute elif gesture.type == Leap.Gesture.TYPE_SCREEN_TAP and ( time.time() - self.prevTime) > self.minTime: tapping = ScreenTapGesture(gesture) win32api.keybd_event(VK_VOLUME_MUTE, code4) self.prevTime = time.time() print "Mute/Unmute"
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() # ParaView parameters normal1 = [ frame.hands[0].palm_normal[x], frame.hands[0].palm_normal[y], frame.hands[0].palm_normal[z] ] # ParaView slice: if only 1 hand and not a fist if len(frame.hands) == 1 and len(frame.hands[0].fingers) > 0: sl.SliceType.Normal = normal1 # ParaView zoom: if 2 hands with each at least 2 fingers elif len( frame.hands) == 2 and len(frame.hands[0].fingers) >= 2 and len( frame.hands[1].fingers) >= 2: cam.Zoom(frame.scale_factor(controller.frame(2))) # ParaView rotate: only attempt if there are 2 hands (at least one must have less than 2 fingers) if len(frame.hands) == 2: # Check for which hand has at least 2 fingers and use that one if len(frame.hands[0].fingers) < 2 and len( frame.hands[1].fingers) > 2: rotHand = frame.hands[1] rollAngle = rotHand.palm_normal.roll * Leap.RAD_TO_DEG azimAngle = rotHand.palm_normal.yaw * Leap.RAD_TO_DEG cam.SetRoll(rollAngle) elif len(frame.hands[1].fingers) < 2 and len( frame.hands[0].fingers) > 2: rotHand = frame.hands[0] rollAngle = rotHand.palm_normal.roll * Leap.RAD_TO_DEG azimAngle = rotHand.palm_normal.yaw * Leap.RAD_TO_DEG cam.SetRoll(rollAngle) #else: #cam.SetRoll(0) Render() 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 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 avg_pos = Leap.Vector() for finger in fingers: avg_pos += finger.tip_position avg_pos /= len(fingers) print "Hand has %d fingers, average finger tip position: %s" % ( len(fingers), avg_pos) # Get the hand's sphere radius and palm position print "Hand sphere radius: %f mm, palm position: %s" % ( hand.sphere_radius, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles print "Hand pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG) # 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: %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 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) 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_string( 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_string(gesture.state), screentap.position, screentap.direction) if not (frame.hands.is_empty and frame.gestures().is_empty): print ""
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() # Get hands for hand in frame.hands: handType = "Left hand" if hand.is_left else "Right hand" # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction palm_position = hand.palm_position ##socket_send msg = ("1 %i %i %i %i") % ( -int(normal.roll * Leap.RAD_TO_DEG/2), -int(direction.pitch * Leap.RAD_TO_DEG/1.4-10), palm_position.y, int(direction.yaw * Leap.RAD_TO_DEG/1.4)) self.sock.send(msg.encode('utf-8')) # Get arm bone arm = hand.arm # Get fingers for finger in hand.fingers: # Get bones for b in range(0, 4): bone = finger.bone(b) # 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 gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keytap = KeyTapGesture(gesture) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture)
def on_frame(self, controller): frame = controller.frame() #global previousId ; #pass global previousId global counter global prevProgress global curList global timer_flag global t_start global t_end global err_counter global step_counter if timer_flag == 0: timer_flag = 1 t_start = time.time() for gesture in frame.gestures(): if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: keyTap = ScreenTapGesture(gesture) #swipeDir = swipe.direction; point = keyTap.pointable finger = Finger(keyTap.pointable) #print "Finger: " + str(finger.type) curList.append(finger.type) #print len(frame.gestures()); #print "Key Tap ID: "+ str(gesture.id)+ " State: "+self.state_names[gesture.state]+ " Position: "+ str(keyTap.position) + " Direction: "+str(keyTap.direction) #print "ID: "+str(circle.id)+" Progress: "+str(circle.progress)+" Radius: "+str(circle.radius)+" Swept Angle: "+str(swept_angle * Leap.RAD_TO_DEG)+" "+clockwiseness oneCount = curList.count(1) twoCount = curList.count(2) gestures = frame.gestures() if ((abs(twoCount - oneCount) >= 1) and findIndexOf(gesture, frame.gestures()) == (len(frame.gestures()) - 1)): if (counter < 20): counter = counter + 1 step_counter = step_counter + 1 print "Counter: " + str(counter) # play audio fileName = str(counter).zfill(2) pygame.mixer.music.load(fileName + '.wav') pygame.mixer.music.play() curList = [] if counter == target_value: t_end = time.time() print t_end - t_start err_counter = err_counter + 1 elif ((abs(twoCount - oneCount) < 1) and findIndexOf(gesture, frame.gestures()) == (len(frame.gestures()) - 1)): if (counter > 1): counter = counter - 1 step_counter = step_counter + 1 print "Counter: " + str(counter) # play audio fileName = str(counter).zfill(2) pygame.mixer.music.load(fileName + '.wav') pygame.mixer.music.play() curList = [] if counter == target_value: t_end = time.time() print t_end - t_start err_counter = err_counter + 1
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())) """ samples = [] sample = [] thumbP = [] cosP = [] # Get hands for hand in frame.hands: handType = "Left hand" if hand.is_left else "Right hand" """ print " %s, id %d, position: %s" % ( handType, hand.id, hand.palm_position) """ # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles """print " pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG) """ cosP.append(math.cos(direction.pitch * Leap.RAD_TO_DEG)) cosP.append(math.cos(normal.roll * Leap.RAD_TO_DEG)) cosP.append(math.cos(direction.yaw * Leap.RAD_TO_DEG)) # Get arm bone arm = hand.arm """ print " Arm direction: %s, wrist position: %s, elbow position: %s" % ( arm.direction, arm.wrist_position, arm.elbow_position) """ # Get fingers for finger in hand.fingers: """ print " %s finger, id: %d, length: %fmm, width: %fmm" % ( self.finger_names[finger.type], finger.id, finger.length, finger.width) """ # Get bones for b in range(0, 4): bone = finger.bone(b) """ print " Bone: %s, start: %s, end: %s, direction: %s" % ( self.bone_names[bone.type], bone.prev_joint, bone.next_joint, bone.direction) """ if b == 0: thumbP.append(bone.prev_joint[0]) thumbP.append(bone.prev_joint[1]) thumbP.append(bone.prev_joint[2]) else: for i in range(0, 3): prevP = (bone.prev_joint[i] - thumbP[i]) / finger.length * cosP[i] nextP = (bone.next_joint[i] - thumbP[i]) / finger.length * cosP[i] sample.append(prevP) sample.append(nextP) #if(sys.argv[1]=="--train"): # print "%f %f" % (prevP,nextP) # Get tools for tool in frame.tools: #print "tool" """ print " Tool id: %d, position: %s, direction: %s" % ( tool.id, tool.tip_position, tool.direction) sample.append(tool.id) for i in range(0,3): sample.append(tool.tip_position[i]) sample.append(tool.direction[i]) """ # Get gestures for gesture in frame.gestures(): #print "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) print "%d %s %f %f %f %s" % ( gesture.id, self.state_names[gesture.state], circle.progress, circle.radius, swept_angle * Leap.RAD_TO_DEG, clockwiseness) sample.append(gesture.id) sample.append(circle.progress) sample.append(circle.radius) sample.append(swept_angle * Leap.RAD_TO_DEG) for i in range(0,3): sample.append(self.state_names[gesture.state][i]) sample.append(clockwiseness[i]) """ 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) print "%d %s %s %s %f" % ( gesture.id, self.state_names[gesture.state], swipe.position, swipe.direction, swipe.speed) sample.append(gesture.id) sample.append(swipe.speed) for i in range(0,3): sample.append(self.state_names[gesture.state][i]) sample.append(swipe.position[i]) sample.append(swipe.direction[i]) """ 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 ) print "%d %s %s %s" % ( gesture.id, self.state_names[gesture.state], keytap.position, keytap.direction ) sample.append(gesture.id) for i in range(0,3): sample.append(self.state_names[gesture.state][i]) sample.append(keytap.position[i]) sample.append(keytap.direction[i]) """ 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 ) print "%d %s %s %s" % ( gesture.id, self.state_names[gesture.state], screentap.position, screentap.direction ) sample.append(gesture.id) sample.append() for i in range(0,3): sample.append(self.state_names[gesture.state][i]) sample.append(screentap.position[i]) sample.append(screentap.direction[i]) """ if not (frame.hands.is_empty and frame.gestures().is_empty): print "" if len(sample) != 0: samples.insert(0, sample) enumm = dict({0: "paper", 1: "scissor", 2: "stone"}) if len(self.predict_buf) >= 10: self.predict_buf = [] self.predict_buf += [enumm[i] for i in self.svc.predict(samples)] self.answer = max(set(self.predict_buf), key=self.predict_buf.count) print self.answer
def on_frame(self, controller): # Defines the conection with the arduino ser = serial.Serial('/dev/ttyACM0', 9600) # 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 " %s, id %d, position: %s" % ( # handType, hand.id, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles # print " pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( # direction.pitch * Leap.RAD_TO_DEG, # normal.roll * Leap.RAD_TO_DEG, # direction.yaw * Leap.RAD_TO_DEG) # Get arm bone arm = hand.arm # print " Arm direction: %s, wrist position: %s, elbow position: %s" % ( # arm.direction, # arm.wrist_position, # arm.elbow_position) # Get fingers indicador = hand.fingers.finger_type(Finger.TYPE_INDEX)[0] mindinho = hand.fingers.finger_type(Finger.TYPE_PINKY)[0] dedao = hand.fingers.finger_type(Finger.TYPE_THUMB)[0] anelar = hand.fingers.finger_type(Finger.TYPE_RING)[0] medio = hand.fingers.finger_type(Finger.TYPE_MIDDLE)[0] ind_apontado_gun = indicador.bone(3).direction.z > 0 ind_apontado = indicador.bone(3).direction.y > 0 med_apontado = medio.bone(3).direction.z > 0 ane_apontado = anelar.bone(3).direction.z > 0 mind_apontado = mindinho.bone(3).direction.z > 0 ded_apontado = dedao.bone(3).direction.y > 0 if ind_apontado and not(med_apontado) and not(ane_apontado) and not(mind_apontado): print "Indicador" ser.write('I') play_sound() sleep(2) elif med_apontado and ind_apontado and not(ane_apontado) and not(mind_apontado): print "Medio e Indicador" ser.write('M') play_sound() sleep(2) elif ane_apontado and ind_apontado and med_apontado and not(mind_apontado): print "Medio, Indicador e Anelar" ser.write('A') play_sound() sleep(2) elif ded_apontado and ind_apontado_gun and not(med_apontado) and not(ane_apontado) and not(mind_apontado): print "Erro de Sistema" ser.write('E') play_sound() sleep(2) # Get tools for tool in frame.tools: print " Tool id: %d, position: %s, direction: %s" % ( tool.id, tool.tip_position, tool.direction) # 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 hand.is_left: print "Swipe mao esquerda" ser.write('L') play_sound() else: print "Swipe mao direita" ser.write('R') play_sound() 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 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())) if not frame.hands.empty: # Get the first hand hand = frame.hands[0] # Check if the hand has any fingers fingers = hand.fingers # Check if there is a fist if hand and fingers.empty: print "We have a fist, so let's make the ball vanish" if ser.isOpen(): ser.write(str(0)) time.sleep(0.3) # if len(frame.hands) == 1 and len(fingers) == 5: # print "We have a one full hand, so let's make the ball appear" # if ser.isOpen(): # ser.write(str(1)) # time.sleep(0.3) if len(frame.hands) == 2 and len(fingers) == 5: print "We have a two full hands, so let's make the balls appear" if ser.isOpen(): ser.write(str(2)) time.sleep(0.3) if len(frame.hands) == 2 and len(fingers) == 2: print "Bye Bye" ##if ser.isOpen(): ## ser.write(str(9)) time.sleep(0.3) if not fingers.empty: # Calculate the hand's average finger tip position avg_pos = Leap.Vector() for finger in fingers: avg_pos += finger.tip_position avg_pos /= len(fingers) ##print "Hand has %d fingers, average finger tip position: %s" % ( ## len(fingers), avg_pos) # Get the hand's sphere radius and palm position ##print "Hand sphere radius: %f mm, palm position: %s" % ( ## hand.sphere_radius, hand.palm_position[0]) #print "Number of Hands: %s - Number of fingers: %s - Palm position: %s" % ( len(frame.hands), len(fingers), hand.palm_position[0]) if len(frame.hands) == 1 and len( fingers) == 5 and -170 < hand.palm_position[0] < -85: print "w5" if ser.isOpen(): ser.write(str(4)) time.sleep(0.3) if len(frame.hands) == 1 and len( fingers) == 5 and -84 < hand.palm_position[0] < 0: print "w10" if ser.isOpen(): ser.write(str(5)) time.sleep(0.3) if len(frame.hands) == 1 and len( fingers) == 5 and 1 < hand.palm_position[0] < 85: print "w15" if ser.isOpen(): ser.write(str(6)) time.sleep(0.3) if len(frame.hands) == 1 and len( fingers) == 5 and 86 < hand.palm_position[0] < 170: print "w20" if ser.isOpen(): ser.write(str(7)) time.sleep(0.3) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles ##print "Hand pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( ## direction.pitch * Leap.RAD_TO_DEG, ## normal.roll * Leap.RAD_TO_DEG, ## direction.yaw * Leap.RAD_TO_DEG) # 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: %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 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) 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_string( gesture.state), keytap.position, keytap.direction) if ser.isOpen(): ser.write(str(3)) time.sleep(0.3) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(gesture)
def on_frame(self, controller): # Get the most recent frame and report some basic information frame = controller.frame() # Check to see that there are hands available if not frame.hands.is_empty: print len(frame.hands), len(frame.hands[1].fingers) print frame.hands[0].palm_normal[0] # ParaView manipulation: adjust slice's normal to that of the first hand in the frame sl.SliceType.Normal = [ frame.hands[0].palm_normal[0], frame.hands[0].palm_normal[1], frame.hands[0].palm_normal[2] ] Render() 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 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 avg_pos = Leap.Vector() for finger in fingers: avg_pos += finger.tip_position avg_pos /= len(fingers) print "Hand has %d fingers, average finger tip position: %s" % ( len(fingers), avg_pos) # Get the hand's sphere Radius=1 and palm position print "Hand sphere Radius=1: %f mm, palm position: %s" % ( hand.sphere_radius, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles print "Hand pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG) # 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: %d, %s, progress: %f, Radius=1: %f, angle: %f degrees, %s" % ( gesture.id, self.state_string( gesture.state), circle.progress, circleradius, 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_string(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_string( 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_string(gesture.state), screentap.position, screentap.direction) if not (frame.hands.is_empty and frame.gestures().is_empty): print ""
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(" %s, id %d, position: %s" % ( # handType, hand.id, hand.palm_position)) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles # print(" pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( # direction.pitch * Leap.RAD_TO_DEG, # normal.roll * Leap.RAD_TO_DEG, # direction.yaw * Leap.RAD_TO_DEG)) # Get arm bone arm = hand.arm # print(" Arm direction: %s, wrist position: %s, elbow position: %s" % ( # arm.direction, # arm.wrist_position, # arm.elbow_position)) joint_angle_array = [direction.pitch, normal.roll, direction.yaw] # Get fingers for finger in hand.fingers: # print(" %s finger, id: %d, length: %fmm, width: %fmm" % ( # self.finger_names[finger.type], # finger.id, # finger.length, # finger.width)) # Get bones prev_bone_direction = None for b in range(0, 4): bone = finger.bone(b) # Structure of the data # bone.direction # is the direction that we are looking for # using the joint angles # bone.direction is a tuple of 3 values # print(f"Bone {b} : value 0") # print(bone.direction) # for example (-0.110091, -0.521456, -0.846146) # print(" Bone: %s, start: %s, end: %s, direction: %s" % ( # self.bone_names[bone.type], # bone.prev_joint, # bone.next_joint, # bone.direction)) if prev_bone_direction is None: prev_bone_direction = np.asarray([ bone.direction[0], bone.direction[1], bone.direction[2] ]) # print("prev_bone_direction") # print(prev_bone_direction) else: curr_bone_direction = np.asarray([ bone.direction[0], bone.direction[1], bone.direction[2] ]) # print("current_bone_direction") # print(curr_bone_direction) joint_angle_bone = np.dot(prev_bone_direction, curr_bone_direction.T) # joint angle bone must be a scalar # print("joint angle") # print(joint_angle_bone) joint_angle_array.append(joint_angle_bone) prev_bone_direction = curr_bone_direction # loop ends when all bone joint angles on each finger gets computed # model execution starts here # input joint angle bones into a PCA latent = np.dot(joint_angle_array, self.pca_matrix) print(latent) # print(latent.shape) # fetch latent into autoencoder # result = model(latent) # print(result) # print("joint_angle_array") # print(joint_angle_array) # with open('./joint_angle_data.csv','a') as fd: # writer = csv.writer(fd) # writer.writerow(joint_angle_array) # Get tools for tool in frame.tools: print("") # print(" Tool id: %d, position: %s, direction: %s" % ( # tool.id, tool.tip_position, tool.direction)) # 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 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 " %s, id %d, position: %s" % (handType, hand.id, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction arm = hand.arm #naoの首が反応する閾値を設定 horizontalLimit = [-30.0, 30.0] verticalLimit = [25.0, 35.0] #手の垂直と水平の値を取得 horizontal = hand.palm_position[0] vertical = hand.palm_position[1] #現在の水平の値が、naoの首の反応する閾値を超えているか判定 & 超えていなければ0を代入 if horizontal > horizontalLimit[1] or horizontal < horizontalLimit[ 0]: naoHorizontal = round( scale(horizontal, (-300.0, 300.0), (1.0, -1.0)), 2) else: naoHorizontal = 0 #現在の垂直の値が、naoの首の反応する閾値を超えているか判定 & 超えていなければ0を代入 if vertical > verticalLimit[1] or vertical < verticalLimit[0]: naoVertical = round( scale(vertical, (0.0, 500.0), (-0.7, +0.7)), 2) else: naoVertical = 0 #現在の垂直の値が、naoの首の反応する閾値を超えているか判定 & 超えていなければ0を代入 if vertical < verticalLimit[1] and vertical > verticalLimit[ 0] and horizontal < horizontalLimit[ 1] and horizontal > horizontalLimit[0]: naoVertical = 0 naoHorizontal = 0 #現在の手の位置を比較し、水平か垂直か決定する if abs(naoVertical) > abs(naoHorizontal): naoHorizontal = 0 elif abs(naoHorizontal) > abs(naoVertical): naoVertical = 0 pass print "横方向 : ", horizontal, ", 縦方向 : ", vertical print "首横 : ", naoHorizontal, ", 首縦 : ", naoVertical # Example showing how to set angles, using a fraction of max speed names = ["HeadYaw", "HeadPitch"] angles = [naoHorizontal, naoVertical] #angles = [0.2, -0.2] fractionMaxSpeed = 0.7 self.motionProxy.setAngles(names, angles, fractionMaxSpeed) time.sleep(0.01) #self.motionProxy.setStiffnesses("Head", 0.0) # Get fingers for finger in hand.fingers: for b in range(0, 4): bone = finger.bone(b) # Get tools for tool in frame.tools: pass # 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 gesture.type == Leap.Gesture.TYPE_SWIPE: swipe = SwipeGesture(gesture) if gesture.type == Leap.Gesture.TYPE_KEY_TAP: keytap = KeyTapGesture(gesture) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP: screentap = ScreenTapGesture(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())) fingers = frame.fingers # Get hands for hand in frame.hands: handType = "Left hand" if hand.is_left else "Right hand" print handType place = 1 if hand.is_left: place = 0 vale = hand.palm_position.y/100 print str(hand.palm_position.y) + " " + str(vale*.65) + " " + str(SampleListener.handplace[place]*.65) same = str(round(vale*.65, 2)) == str(round(SampleListener.handplace[place]*.65, 2)) word = "" string = "" leniancy = 1 if same: word = "STAY" string = handType + ": NO CHANGE" elif SampleListener.handplace[place] < vale: word = "UP" string = handType + ": UP" elif SampleListener.handplace[place] > vale: word = "DOWN" string = handType + ": DOWN" else: word = "STAY" string = handType + ": NO CHANGE" SampleListener.handplace[place] = vale newplaceonpong = float(SampleListener.pongheight/SampleListener.motionLimit) * hand.palm_position.y SampleListener.pongplacement[place] = newplaceonpong print " ( " + word + " ) PLACE: " + str(newplaceonpong) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Get gestures for gesture in frame.gestures(): #print "Left hand" if gesture.hands[0].is_left else "Right hand" 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 " 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)
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 " %s, id %d, position: %s" % (handType, hand.id, hand.palm_position) # Get the hand's normal vector and direction normal = hand.palm_normal direction = hand.direction # Calculate the hand's pitch, roll, and yaw angles print " pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( direction.pitch * Leap.RAD_TO_DEG, normal.roll * Leap.RAD_TO_DEG, direction.yaw * Leap.RAD_TO_DEG) # Get arm bone arm = hand.arm print " Arm direction: %s, wrist position: %s, elbow position: %s" % ( arm.direction, arm.wrist_position, arm.elbow_position) # Get fingers for finger in hand.fingers: print " %s finger, id: %d, length: %fmm, width: %fmm" % ( self.finger_names[finger.type], finger.id, finger.length, finger.width) # Get bones for b in range(0, 4): bone = finger.bone(b) print " Bone: %s, start: %s, end: %s, direction: %s" % ( self.bone_names[bone.type], bone.prev_joint, bone.next_joint, bone.direction) # Get tools for tool in frame.tools: print " Tool id: %d, position: %s, direction: %s" % ( tool.id, tool.tip_position, tool.direction) # 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 "" time.sleep(0.1)
def on_frame(self, controller): frame = controller.frame() # print "Gestes reconnus : %d" % (len(frame.gestures())) # Get hands if len(frame.hands) == 0: self.sendMSG(-1,["positionMain"]) else: hand = frame.hands[0] distance = math.sqrt(hand.palm_position[1]*hand.palm_position[1] + hand.palm_position[2]*hand.palm_position[2] + hand.palm_position[3]*hand.palm_position[3]) self.sendMSG(distance,["positionMain"]) # 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 = "trigo" else: clockwiseness = "horaire" if circle.state is Leap.Gesture.STATE_START and self.isCircleComplete: print "starting circle "+clockwiseness self.isCircleComplete = False; self.sendMSG("bang",["events","circle",clockwiseness,"start"]) if circle.state is Leap.Gesture.STATE_STOP and not self.isCircleComplete: print "stopping circle "+clockwiseness self.isCircleComplete = True; self.sendMSG("bang",["events","circle",clockwiseness,"stop"]) if gesture.type == Leap.Gesture.TYPE_SWIPE and not self.isTimerRunning: swipe = SwipeGesture(gesture) self.startAsyncTimer(); isHorizontal = abs(swipe.direction[0]) > abs(swipe.direction[1]) if(isHorizontal): if(swipe.direction[0] > 0): swipeDirection = "right" else: swipeDirection = "left" else: if(swipe.direction[1] > 0): swipeDirection = "up"; else: swipeDirection = "down"; print "swipe "+swipeDirection+" occurred" self.sendMSG("events",["bang","swipe",swipeDirection]) if gesture.type == Leap.Gesture.TYPE_KEY_TAP and not self.isTimerRunning: keytap = KeyTapGesture(gesture) self.startAsyncTimer(); print "keytap occurred" self.sendMSG("bang",["events","keytap"]) if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP and not self.isTimerRunning: screentap = ScreenTapGesture(gesture) self.startAsyncTimer(); print "screentap occurred" self.sendMSG("bang",["events","screentap"])