Esempio n. 1
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:

            # Gestures
            for gesture in frame.gestures():

                if gesture.type == Leap.Gesture.TYPE_SWIPE:
                    #swipe = SwipeGesture(gesture)
                    print('Swiping!')
                    data_to_send('1')
                    time.sleep(2)

                elif gesture.type == Leap.Gesture.TYPE_SWIPE:
                    circle = CircleGesture(gesture)
                    print('circle!')
                    # 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

                    data_to_send('2')
                    time.sleep(2)
Esempio n. 2
0
    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):
        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)   
Esempio n. 4
0
    def cal_distance(vector1, vector2):
        dist = 

        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 = "counterclockwise"

                print "Circle "+ clockwiseness
            if gesture.type == Leap.Gesture.TYPE_KEY_TAP:
                keytap = CircleGesture(gesture)
                print "Key Tap"
            if gesture.type == Leap.Gesture.TYPE_SWIPE:
                swipe = CircleGesture(gesture)
                print "Swipe"
            if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP:
                swipe = CircleGesture(gesture)
                start = swipe.start_position
                current = swipe.position
                # direction = swipe.direction doesn't really work
                print "Screen Tap "+direction+"!"
                    if current - start
    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)
Esempio n. 6
0
    def cal_distance(vector1, vector2):
        # dist =

        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 = "counterclockwise"

                ser.write('Circle ' + clockwiseness)
            if gesture.type == Leap.Gesture.TYPE_KEY_TAP:
                keytap = CircleGesture(gesture)
                ser.write('Key Tap')
            if gesture.type == Leap.Gesture.TYPE_SWIPE:
                swipe = CircleGesture(gesture)
                start = swipe.start_position
                current = swipe.position
                # direction = swipe.direction doesn't really work
                ser.write('Swipe')
            if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP:
                ser.write('Screen Tap ' + direction)

        #if not (frame.hands.is_empty and frame.gestures().is_empty):
        #   print ""
        def state_string(self, state):
            if state == Leap.Gesture.STATE_START:
                return "STATE_START"
            if state == Leap.Gesture.STATE_UPDATE:
                return "STATE_UPDATE"
            if state == Leap.Gesture.STATE_INVALID:
                return "STATE_INVALID"
Esempio n. 7
0
    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 ""
Esempio n. 8
0
    def on_frame(self, controller):
        # Get the most recent frame and report some basic information
        frame = controller.frame()

        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)
#                 print int(avg_pos.x % 255),",",int(avg_pos.y % 255),",",int(avg_pos.z % 255)
#                 print "sleeping"
                time.sleep(.25)
#                 global ser
                
                print str( str(int(avg_pos.x % 255)) + "," + str(int(avg_pos.y % 255))+ "," + str(int(avg_pos.z % 255) ))
                ser.write(str( str(int(avg_pos.x % 255)) + "," + str(int(avg_pos.y % 255))+ "," + str(int(avg_pos.z % 255)) + '\n'))

# 				print ave_pos


            # Get the hand's normal vector and direction
            normal = hand.palm_normal
            direction = hand.direction



            # 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
    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)
Esempio n. 10
0
	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
Esempio n. 11
0
    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))
Esempio n. 12
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 ""
Esempio n. 13
0
def please(frame):
    global lastWord
    for hand in frame.hands:
        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) == False:
                    #                    print "1"
                    if hand.is_right:
                        #                        print "2"
                        if circle.state != Leap.Gesture.STATE_START:
                            #                            print "3"
                            if hand.palm_normal.roll * Leap.RAD_TO_DEG <= -65 and hand.palm_normal.roll * Leap.RAD_TO_DEG >= -115:
                                #                                print "4"
                                #                                print hand.direction.yaw * Leap.RAD_TO_DEG
                                if abs(hand.direction.yaw * Leap.RAD_TO_DEG +
                                       65) <= 30:
                                    #                                    print "5"
                                    if circle.progress >= 1.5:
                                        if lastWord != 'please':
                                            lastWord = 'please'
                                            print 'please'
                                            return True
    return False
Esempio n. 14
0
def area(frame):
    global lastWord
    op = False
    for hand in frame.hands:
        for gesture in frame.gestures():
            if gesture.type == Leap.Gesture.TYPE_CIRCLE:
                circle = CircleGesture(gesture)

                # yaw = -90 roll = 90
                if (circle.pointable.direction.angle_to(circle.normal) <=
                        Leap.PI / 2) == True:
                    #                    print "\n1"
                    if hand.is_right:
                        #                        print "\n2"
                        swept_angle = 0
                        if circle.state != Leap.Gesture.STATE_START:
                            #                            print "\n3"
                            #                            print " Roll : " + str(hand.palm_normal.roll * Leap.RAD_TO_DEG) + " "
                            #previous = CircleGesture(controller.frame(1).gesture(circle.id))
                            #swept_angle = (circle.progress - previous.progress) * 2 * Leap.PI
                            if abs(hand.palm_normal.roll
                                   ) * Leap.RAD_TO_DEG <= 45:
                                #                                print "\n4"
                                #                                print hand.direction.yaw * Leap.RAD_TO_DEG
                                if abs(hand.direction.yaw
                                       ) * Leap.RAD_TO_DEG <= 45:
                                    if circle.progress >= 1.75:
                                        #                                        print "\n5"
                                        op = True
    if op:
        lastWord = "area"
        print 'area'
Esempio n. 15
0
    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_CIRCLE:
                data['Gesture'] = 'circle'
                print('SCANNING')
                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:
                    data['Clock'] = "clockwise"
                else:
                    data['Clock'] = "counterclockwise"
            if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP:
                publish.single("homewatchtest-door",
                               'hola',
                               hostname="test.mosquitto.org")
                print('OPENING DOOR')
            if gesture.type == Leap.Gesture.TYPE_KEY_TAP:
                now = datetime.datetime.now()
                print(str(now))
                data2 = "Current year: %d" % now.year + "              ,Current month: %d" % now.month + "         ,Current day: %d" % now.day
                engine.say(data2)
                engine.runAndWait()
Esempio n. 16
0
    def on_frame(self, controller):
        frame = controller.frame()
        pygame.draw.circle(self.screen, (255, 0, 0), (10, 10), 10)

        for hand in frame.hands:
            pygame.draw.circle(self.screen, (0, 255, 0), (10, 10), 10)

        for gesture in frame.gestures():
            if gesture.type == Leap.Gesture.TYPE_CIRCLE:
                print "circle detected"
                circle = CircleGesture(gesture)

                if circle.pointable.direction.angle_to(
                        circle.normal) <= Leap.PI / 2:
                    clockwiseness = "clockwise"
                    massageOn = True
                else:
                    clockwiseness = "counter-clockwise"
                    massageOn = False
                print clockwiseness

            if circle.progress >= 0.8:
                if massageOn:
                    pygame.draw.circle(self.screen, (0, 200, 0), (650, 350),
                                       220, 20)
                else:
                    pygame.draw.circle(self.screen, (255, 0, 0), (650, 350),
                                       220, 20)
Esempio n. 17
0
def please(frame):
    global lastWord
    for hand in frame.hands:
        for gesture in frame.gestures():
            if gesture.type == Leap.Gesture.TYPE_CIRCLE:
                circle = CircleGesture(gesture)

                # yaw = -90 roll = 90
                if (circle.pointable.direction.angle_to(circle.normal) <= Leap.PI / 2) == False:
                    # print "\n1"
                    if hand.is_right:
                        # print "\n2"
                        # swept_angle = 0
                        if circle.state != Leap.Gesture.STATE_START:
                            # print "\n3"
                            # print " Roll : " + str(hand.palm_normal.roll * Leap.RAD_TO_DEG) + " "
                            # previous = CircleGesture(controller.frame(1).gesture(circle.id))
                            # swept_angle = (circle.progress - previous.progress) * 2 * Leap.PI
                            if hand.palm_normal.roll * Leap.RAD_TO_DEG <= -65 and hand.palm_normal.roll * Leap.RAD_TO_DEG >= -115:
                                # print "\n4"
                                if hand.direction.yaw * Leap.RAD_TO_DEG >= -115 and hand.direction.yaw * Leap.RAD_TO_DEG <= -65:
                                    if circle.progress >= 1.75:
                                        lastWord = "please"
                                        print 'please'
                                        return
Esempio n. 18
0
    def on_frame(self, controller):

        clockwiseness = 0
        frame = controller.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 = 1
                else:
                    clockwiseness = 0

        if not (frame.hands.is_empty and frame.gestures().is_empty):

            xAxis = round(frame.hands[0].direction[0], 2)
            yAxis = round(frame.hands[0].arm.wrist_position[1], 2)
            zAxis = round(frame.hands[0].arm.wrist_position[2], 2)

            set_xAxis = int((600 - ((xAxis / 1.98) * 450)) - 150 )
            set_yAxis = int(375 - (100 * (yAxis / 360)))
            set_zAxis = int(275 + (((zAxis + 50) / 200) * 200))

            tev_json_obj = json.dumps({'frameId':frame.id, 'coordinates':{'xAxis':set_xAxis,'yAxis':set_yAxis, 'zAxis': set_zAxis, 'clockwiseness': clockwiseness}})
            print(tev_json_obj)

            counter = str(frame.id)
            counter = counter[-1:]
            if counter == '1' and self.mqttc != None:
                self.mqttc.publish(AWS_IOT_TOPIC, tev_json_obj, 0, False)
Esempio n. 19
0
    def on_frame(self, controller):
        # Get the most recent frame and report some basic information
        frame = controller.frame()
        if self.run:
            # Get gestures
            #print'dhg'
            for gesture in frame.gestures():
                if gesture.type == Leap.Gesture.TYPE_CIRCLE:
                    circle = CircleGesture(gesture)
                    state = self.state_names[gesture.state]
                    # 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"
                        if state is 'STATE_END':
                            print '%d' % int(circle.progress)
                            self.subpass += '%d' % int(circle.progress)

                    else:
                        clockwiseness = "counterclockwise"
                        if state is 'STATE_END':
                            print '%d' % int(circle.progress)
                            self.subpass_ += '%d' % int(circle.progress)
            #print self.subpass
            if (frame.hands.is_empty and frame.gestures().is_empty
                    and (self.subpass != '' or self.subpass_ != '')):
                self.password = self.subpass + self.subpass_
                print self.password
                self.run = False
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
Esempio n. 21
0
    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:
            if not hand.is_left:
                position = hand.fingers.frontmost.tip_position
                self.drawPosition = (2 * int(position[0]),
                                     480 - int(position[1]))
                minDistance = 100
                for finger in hand.fingers:
                    distance = finger.tip_position[2] - position[2]
                    self.is_drawing = distance > 0 and distance < 25
                    if distance < minDistance and distance > 0:
                        minDistance = distance
                    if self.is_drawing:
                        break

        # Get gestures
        for gesture in frame.gestures():
            if gesture.type == Leap.Gesture.TYPE_CIRCLE:
                if self.previousID == gesture.id:
                    continue
                self.previousID = gesture.id
                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)
Esempio n. 22
0
    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 ))
Esempio n. 23
0
 def check_circle(self, frame):
     if len(frame.gestures()) > 0:
         for g in frame.gestures():
             if g.type == Leap.Gesture.TYPE_CIRCLE and CircleGesture(
                     g).progress > SELECT_CIRCLE_LENGTH:
                 if g.hands[0].is_left:
                     self.move = "select"
                 else:
                     self.move = "start"
Esempio n. 24
0
    def on_frame(self, controller):
        # Get the most recent frame and report some basic information
        frame = controller.frame()
        
        if not frame.is_valid:
            return
        
        if len(frame.hands) == 0:
            for value in self.values.itervalues():
                value.set(0)
            return
        
        if len(frame.hands) > 1:
            return
        
        previous = controller.frame(10)

        ignore_changes = False
        
        # Get gestures
        for gesture in frame.gestures():
            if gesture.type == Leap.Gesture.TYPE_CIRCLE:
                if gesture.state == Leap.Gesture.STATE_START or gesture.state == Leap.Gesture.STATE_UPDATE:
                    # if we're doing a circle, ignore individual measurements in order to avoid noise
                    ignore_changes = True
                elif gesture.state == Leap.Gesture.STATE_STOP:
                    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"

                    ignore_changes = False
   
        if not ignore_changes:
            # Get hands
            for hand in frame.hands:
                # Get the hand's normal vector and direction
                normal = hand.palm_normal
                direction = hand.direction
    
                # Calculate the hand's pitch, roll, and yaw angles
                pitch = direction.pitch * Leap.RAD_TO_DEG
                roll = normal.roll * Leap.RAD_TO_DEG
                yaw = direction.yaw * Leap.RAD_TO_DEG

                self.values["pitch"].set(pitch)
                self.values["roll"].set(roll)
                self.values["yaw"].set(yaw)

            if previous.is_valid:
                #for hand in frame.hands:
                translation = frame.translation(previous)
                if translation.is_valid:
                    self.values["elevation"].set(translation.y)
Esempio n. 25
0
def mom_grandma_dad_grandpa(frame):
    global lastWord
    for hand in frame.hands:
        if hand.sphere_radius > 80:
            handChirality = 1 if hand.is_right else -1
            if (handChirality*hand.palm_normal).angle_to(Leap.Vector(-1,0,0)) < Leap.PI/6:
                if Leap.PI/6 < hand.direction.angle_to(Leap.Vector(0,0,-1)) < 3*Leap.PI/8:
                    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) if handChirality == -1 else not (
                                circle.pointable.direction.angle_to(circle.normal) <= Leap.PI / 2):  # clockwise
                                if circle.state != Leap.Gesture.STATE_START:
                                    if circle.progress >= 1.25:
                                        if lastWord != "grandma":
                                            time.sleep(0.5)
                                            print "grandma"
                                            lastWord = "grandma"
                                            return True
                    if lastWord != "mom":
                        time.sleep(0.5)
                        print "mom"
                        lastWord = "mom"
                        return True
                if 5*Leap.PI/12 < hand.direction.angle_to(Leap.Vector(0,0,-1)) < 2*Leap.PI/3:
                    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) if handChirality == -1 else not (
                                circle.pointable.direction.angle_to(circle.normal) <= Leap.PI / 2):  # clockwise
                                if circle.state != Leap.Gesture.STATE_START:
                                    if circle.progress >= 1.25:
                                        if lastWord != "grandpa":
                                            print "grandpa"
                                            lastWord = "grandpa"
                                            return True
                    if lastWord != "dad":
                        print "dad"
                        lastWord = "dad"
                        return True
        return False
Esempio n. 26
0
    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
Esempio n. 27
0
    def on_frame(self, controller):
        frame = controller.frame()
        clockwiseness = ''
        keyboard1 = Controller()
        count = 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'

                print 'ID: ' + str(circle.id) + clockwiseness

                if clockwiseness == 'counter-clockwise':
                    altTab()
                    playScratch()
                    altTab()

                if clockwiseness == 'clockwise':
                    altTab()
                    playScratchForward()
                    altTab()

        for hand in frame.hands:
            handType = 'Left Hand' if hand.is_left else 'Right Hand'
            print handType
            print 'Height: ' + str(hand.palm_position.y)
            pitchValue = hand.palm_position.y
            hold = 0
            time.sleep(.3)

            if (hold == 0):

                if (handType == 'Right Hand' and pitchValue < 75):
                    altTab()
                    playPause()
                    altTab()
                    hold = 1

                if (handType == 'Left Hand' and pitchValue < 75):
                    altTab()
                    altSpace()
                    altTab()
                    hold = 1

            if (hold == 1):
                hold = 0
    def detect_rotation(self, controller, gesture):
        if gesture.type == Leap.Gesture.TYPE_CIRCLE:
            circle = CircleGesture(gesture)
            if circle.pointable.direction.angle_to(
                    circle.normal) <= Leap.PI / 2:
                is_clockwise = True
            else:
                is_clockwise = False

            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.progress > 1.3:
                    if is_clockwise:
                        return self.action_handler.ROLL_FORWARD
                    else:
                        return self.action_handler.ROLL_BACKWARD
        return None
Esempio n. 29
0
 def on_frame(self, controller):
     frame = controller.frame() # atribuindo a variavel frame o retorno de informações dos ultimos qudros captadas pelo leap motion
     #frame_penultimo_gesto = controller.frame(1) # atribuindo a variavel frame_penultimo_gesto o retorno de informações do penultimo gesto
     for hand in frame.hands:
         for gesture in frame.gestures():
             #cada gesto tem seu ID criado
             if gesture.type == Leap.Gesture.TYPE_CIRCLE:
                 circle= CircleGesture(gesture) 
                 #instanciando o objeto da classe gesto circulo
                 # aqui o movimento circular é o de rotacionar o dedo na frente do computador
                 if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/2:
                     clockwiseness= "clockwise" # indica que o circulo esta em sentido horario
                 else:
                     clockwiseness= "counter-clockwise" #indica que o circulo esta em sentido anti
                     #swept angle vai dizer o qual longe vc foi no circulo desde a ultimo circulo identificado
                     
                 swept_angle = 0
                 if circle.state != Leap.Gesture.STATE_START:
                     previous = CircleGesture(controller.frame(1).gesture(circle.id)) #criando um novo frame ao escrever frame(1)
                     swept_angle = (circle.progress - previous.progress) * 2 * Leap.PI
                 # imprime no console o tamanho do circulo que voê gesticula e o sentido horario ou anti-horario                        
                 print "Raio: " + str(circle.radius) + " Sentido do Círculo: " + clockwiseness
 def on_frame(self, controller):  
     music = Music_Control()  
     frame = controller.frame()  
     for gesture in frame.gestures():  
         # -----------------------------------------------------------------------  
         if gesture.type == Leap.Gesture.TYPE_CIRCLE:  
             circle = CircleGesture(gesture)  
             if self.isClockwise(circle.pointable.direction.angle_to(circle.normal)):  
                 music.increaseVolume()  
             else:  
                 music.decreaseVolume()  
         # -----------------------------------------------------------------------  
         if gesture.type is Leap.Gesture.TYPE_SWIPE:  
             swipe = Leap.SwipeGesture(gesture)