Пример #1
0
def main(osc_setup, watched_params_in_hand):

    print "----------------------------------Initializing ----------------------------------"
    print


    #print "Get an actor for sending OSC messages."
    actor = Sender(osc_setup)

    #print "Get a hands listener and bind it with the actor."
    listener = Hands_Listener(actor,watched_params_in_hand) #Get listener which herits from Leap.Listener

    #print "Get a Leap controller."
    controller = Leap.Controller()  #Get a Leap controller

    #print "Binding the Listener to the controller."

    controller.add_listener(listener)  #Attach the listener
    

    #Keep this process running until Enter is pressed
    
    
    print "Press Enter to quit..."
    print
    print "---------------------------------- Running ----------------------------------"
    
    sys.stdin.readline()
    
    #Remove the sample listener when done
    controller.remove_listener(listener)
Пример #2
0
def main(short_moves):

    print "----------------------------------ShortMotion----------------------------------"

    print "Get an actor for lauching commands."
    actor = Actor(short_moves)

    print "Get a hands listener and bind it with the actor."
    listener = Hands_Listener(
        actor)  #Get listener which herits from Leap.Listener

    print "Get a Leap controller."
    controller = Leap.Controller()  #Get a Leap controller

    print "Binding the Listener to the controller."
    controller.add_listener(listener)  #Attach the listener

    print "----------------------------------Short Moves-----------------------------------"
    print ""
    actor.print_short_moves()
    print ""

    #Keep this process running until Enter is pressed
    print "Press Enter to quit..."
    sys.stdin.readline()

    #Remove the sample listener when done
    controller.remove_listener(listener)
Пример #3
0
def main():
    if "-h" in sys.argv or "--help" in sys.argv:
        show_help()
        return

    print "----------------------------------PyLeapMouse----------------------------------"
    print "Use --finger (or blank) for pointer finger control, and --palm for palm control."
    print "Use -h or --help for more info.\n"

    #Default
    finger_mode = True
    palm_mode = False
    motion_mode = False
    smooth_aggressiveness = 8
    smooth_falloff = 1.3

    for i in range(0, len(sys.argv)):
        arg = sys.argv[i].lower()
        if "--palm" in arg:
            finger_mode = False
            palm_mode = True
            motion_mode = False
        if "--motion" in arg:
            finger_mode = False
            palm_mode = False
            motion_mode = True
        if "--smooth-falloff" in arg:
            smooth_falloff = float(sys.argv[i + 1])
        if "--smooth-aggressiveness" in arg:
            smooth_aggressiveness = int(sys.argv[i + 1])

    listener = None
    #I'm tired and can't think of a way to organize this segment nicely

    #Create a custom listener object which controls the mouse
    if finger_mode:  #Finger pointer mode
        listener = Finger_Control_Listener(
            Mouse,
            smooth_aggressiveness=smooth_aggressiveness,
            smooth_falloff=smooth_falloff)
        print "Using finger mode..."
    elif palm_mode:  #Palm control mode
        listener = Palm_Control_Listener(Mouse)
        print "Using palm mode..."
    elif motion_mode:  #Motion control mode
        listener = Motion_Control_Listener(Mouse)
        print "Using motion mode..."

    controller = Leap.Controller()  #Get a Leap controller
    print "Adding Listener."
    controller.add_listener(listener)  #Attach the listener

    #Keep this process running until Enter is pressed
    print "Press Enter to quit..."
    sys.stdin.readline()
    #Remove the sample listener when done
    controller.remove_listener(listener)
Пример #4
0
def main():
    controller = Leap.Controller()
    time.sleep(2)
    print(controller.is_connected)
    controller.set_policy_flags(Leap.Controller.POLICY_IMAGES)
    try:
        #run(controller)
        run()
    except KeyboardInterrupt:
        sys.exit(0)
Пример #5
0
def main():
    controller.enable_gesture(Leap.Gesture.TYPE_SWIPE)
    #Default
    finger_mode = False
    palm_mode = True
    motion_mode = False
    smooth_aggressiveness = 8
    smooth_falloff = 1.3

    listener = Palm_Control_Listener(Mouse)
    controller = Leap.Controller()  #Get a Leap controller
    controller.set_policy_flags(Leap.Controller.POLICY_BACKGROUND_FRAMES)
    controller.add_listener(listener)  #Attach the listener

    #Keep this process running until Enter is pressed
    print "Press Enter to quit..."
    sys.stdin.readline()
    #Remove the sample listener when done
    controller.remove_listener(listener)
Пример #6
0
def main(osc_setup):

    print "----------------------------------Initializing ----------------------------------"
    print

    actor = Sender(osc_setup)
    listener = Hands_Listener(
        actor)  #Get listener which herits from Leap.Listener
    controller = Leap.Controller()  #Get a Leap controller

    print "Waiting for the Leap..."
    print

    controller.add_listener(listener)  #Attach the listener

    print "Press Enter to quit..."
    print
    print "---------------------------------- Running ----------------------------------"

    sys.stdin.readline()

    #Remove the sample listener when done
    controller.remove_listener(listener)
Пример #7
0
def main():

    controller = Leap.Controller()

    # Enable swipe gesture
    controller.enable_gesture(Leap.Gesture.TYPE_SWIPE)
    controller.config.set("Gesture.Swipe.MinLength", 40.0)
    controller.config.set("Gesture.Swipe.MinVelocity", 40)
    controller.config.save()

    listener = Listener()
    controller.add_listener(listener)

    keyboard = Registration().register()
    parser = Parser(keyboard)
    parser.run()
    #Keep this process running until Enter is pressed
    print "Press Enter to quit..."
    try:
        sys.stdin.readline()
    except KeyboardInterrupt:
        pass
    finally:
        controller.remove_listener(listener)
Пример #8
0
def run(debug=False):

    controller = Leap.Controller()
    time.sleep(2)
    print(controller.is_connected)
    controller.set_policy_flags(Leap.Controller.POLICY_IMAGES)
    counter = -20
    maps_initialized = False
    previous_sum = 0
    current_sum = 0
    baseline = 0

    executor = ThreadPoolExecutor(max_workers=1)
    id_ = ''
    with open('id.txt', 'r+') as f:
        id_ = f.readline()

    id_ = re.search(r'(\d+)', id_).group(0)
    print('the real id is', id_)
    # Set the baseline
    print('Calibrating, please wait...')
    while counter < 0:
        frame = controller.frame()
        image = frame.images[0]
        if image.is_valid:
            if not maps_initialized:
                left_coordinates, left_coefficients = convert_distortion_maps(
                    frame.images[0])
                right_coordinates, right_coefficients = convert_distortion_maps(
                    frame.images[1])

                maps_initialized = True

            undistorted_left = undistort(image, left_coordinates,
                                         left_coefficients, 400, 400)
            undistorted_right = undistort(image, right_coordinates,
                                          right_coefficients, 400, 400)

            newsum = sum([
                image.data[i] for i in range(0, image.width * image.height, 50)
            ])
            #print('Counter:', counter, '| Val:', newsum)
            if counter >= -17:
                baseline += newsum
            # ba = bytearray(image.data)
            # print(sum(ba))
            counter += 1
            # cv2.imshow('Left Camera', undistorted_left)
            # cv2.imshow('Right Camera', undistorted_right)

            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        #print(counter)

    baseline /= 17
    mult = 1.03
    print('Done!')
    if debug:
        print('Baseline: {:,}, Threashhold: {}'.format(baseline,
                                                       baseline * mult))
    onspike = False
    while (True):
        frame = controller.frame()
        #print(frame.current_frames_per_second)
        image = frame.images[0]
        if image.is_valid:
            if not maps_initialized:
                left_coordinates, left_coefficients = convert_distortion_maps(
                    frame.images[0])
                right_coordinates, right_coefficients = convert_distortion_maps(
                    frame.images[1])

                maps_initialized = True

            undistorted_left = undistort(image, left_coordinates,
                                         left_coefficients, 400, 400)
            undistorted_right = undistort(image, right_coordinates,
                                          right_coefficients, 400, 400)

            #display images

            #buffer_size = image.bytes_per_pixel * image.width * image.height
            #print(sum([image.data[i] for i in range(0,image.width*image.height,20)]))
            #pprint(image.data_pointer)
            if counter % 1 == 0:
                previous_sum = current_sum
                current_sum = sum([
                    image.data[i]
                    for i in range(0, image.width * image.height, 50)
                ])
                # print('{:,}'.format(current_sum), '|', '{:,}'.format(current_sum - previous_sum))
                if debug:
                    print(abs(current_sum))  #-previous_sum))
                if (abs(current_sum) >
                        mult * baseline) and previous_sum != 0 and not onspike:
                    print('Trashed!')
                    executor.submit(updater.addone, id_)
                    onspike = True
                elif not abs(current_sum) > mult * baseline:
                    onspike = False
                counter = 0

            # ba = bytearray(image.data)
            # print(sum(ba))
            counter += 1
            if debug:
                cv2.imshow('Left Camera', undistorted_left)
                cv2.imshow('Right Camera', undistorted_right)

            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
Пример #9
0
 def __init__(self):
     self.keep_tracking = False
     self.listener = GestureListener()
     self.controller = Leap.Controller()