Example #1
0
 def __init__(self):
     super(ObjectController, self).__init__()
     self.nb_hands = MixedFilter(
         [NoiseFilter(10, 0.3, 10),
          LowpassFilter(0.5)])
     self.grab = GrabLogic()
     self.scale = ScaleLogic()
Example #2
0
class ObjectController(Leap.Listener):
    def __init__(self):
        super(ObjectController, self).__init__()
        self.nb_hands = MixedFilter([
            NoiseFilter(10, 0.3, 10),
            LowpassFilter(0.5)])
        self.grab = GrabLogic()
        self.scale = ScaleLogic()

    def on_init(self, controller):
        pass

    def on_exit(self, controller):
        pass

    def on_frame(self, controller):
        frame = controller.frame()
        self.nb_hands.add_value(len(frame.hands))

        # 1 hand for grab, 2 for scale
        if self.nb_hands.around(1, 0.1):
            self.grab.frame(frame)
        elif self.nb_hands.around(2, 0.1):
            self.scale.frame(frame)
        else:
            self.grab.reset()
            self.scale.reset()
Example #3
0
class ObjectController(Leap.Listener):
    def __init__(self):
        super(ObjectController, self).__init__()
        self.nb_hands = MixedFilter(
            [NoiseFilter(10, 0.3, 10),
             LowpassFilter(0.5)])
        self.grab = GrabLogic()
        self.scale = ScaleLogic()

    def on_init(self, controller):
        pass

    def on_exit(self, controller):
        pass

    def on_frame(self, controller):
        frame = controller.frame()
        self.nb_hands.add_value(len(frame.hands))

        # 1 hand for grab, 2 for scale
        if self.nb_hands.around(1, 0.1):
            self.grab.frame(frame)
        elif self.nb_hands.around(2, 0.1):
            self.scale.frame(frame)
        else:
            self.grab.reset()
            self.scale.reset()
Example #4
0
 def __init__(self):
     self.is_activated = False
     self.two_hands_grabbing = gestures.TwoHandsGrabbing()
     self.magnitude = MixedFilter([
         #NoiseFilter(1000, 100, 20),
         LowpassFilter(0.05)
     ])
     self.magnitude_origin = 0
Example #5
0
 def __init__(self):
     self.grabbing_hands = {}
     self.first_hand_closed = MixedFilter([
         #NoiseFilter(2, 100, 20),
         LowpassFilter(0.1)
     ])
     self.second_hand_closed = MixedFilter([
         #NoiseFilter(2, 100, 20),
         LowpassFilter(0.1)
     ])
Example #6
0
 def __init__(self):
     self.grabbing_hands = {}
     self.first_hand_closed = MixedFilter(
         [
             # NoiseFilter(2, 100, 20),
             LowpassFilter(0.1)
         ]
     )
     self.second_hand_closed = MixedFilter(
         [
             # NoiseFilter(2, 100, 20),
             LowpassFilter(0.1)
         ]
     )
Example #7
0
class ClosingHand(object):
    def __init__(self):
        self.nb_fingers = MixedFilter([NoiseFilter(100, 0.3, 10), LowpassFilter(0.9)])

    def frame(self, hand):
        fingers = hand.fingers
        self.nb_fingers.add_value(len(fingers))

    def reset(self):
        self.nb_fingers.empty()

    def is_done(self):
        if self.nb_fingers.around(3.0, 0.5) and self.nb_fingers.derivative < -0.012:
            return True
        return False
Example #8
0
 def __init__(self):
     self.is_activated = False
     self.two_hands_grabbing = gestures.TwoHandsGrabbing()
     self.magnitude = MixedFilter([
         #NoiseFilter(1000, 100, 20),
         LowpassFilter(0.05)])
     self.magnitude_origin = 0
Example #9
0
 def __init__(self):
     super(ObjectController, self).__init__()
     self.nb_hands = MixedFilter([
         NoiseFilter(10, 0.3, 10),
         LowpassFilter(0.5)])
     self.grab = GrabLogic()
     self.scale = ScaleLogic()
Example #10
0
class ClosingHand(object):
    def __init__(self):
        self.nb_fingers = MixedFilter(
            [NoiseFilter(100, 0.3, 10),
             LowpassFilter(0.9)])

    def frame(self, hand):
        fingers = hand.fingers
        self.nb_fingers.add_value(len(fingers))

    def reset(self):
        self.nb_fingers.empty()

    def is_done(self):
        if self.nb_fingers.around(3.0, 0.5) \
                and self.nb_fingers.derivative < -0.012:
            return True
        return False
Example #11
0
class ScaleLogic(object):
    def __init__(self):
        self.is_activated = False
        self.two_hands_grabbing = gestures.TwoHandsGrabbing()
        self.magnitude = MixedFilter([
            #NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05)
        ])
        self.magnitude_origin = 0

    def frame(self, frame):
        first_hand, second_hand = frame.hands[0], frame.hands[1]
        self.two_hands_grabbing.frame((first_hand, second_hand))
        if not self.is_activated:
            if self.two_hands_grabbing.just_grabbed():
                self.start(first_hand, second_hand)
        else:
            if self.two_hands_grabbing.just_lost():
                self.stop()
            else:
                self.run(first_hand, second_hand)

    def start(self, first_hand, second_hand):
        self.is_activated = True
        send_command('object_scale_origin')
        dis = first_hand.stabilized_palm_position - second_hand.stabilized_palm_position
        self.magnitude_origin = dis.magnitude

    def stop(self):
        self.is_activated = False
        self.two_hands_grabbing.reset()

    def run(self, first_hand, second_hand):
        dis = first_hand.stabilized_palm_position - second_hand.stabilized_palm_position
        self.magnitude.add_value(dis.magnitude)
        mag = self.magnitude.value / self.magnitude_origin
        send_command('object_scale', {'sx': mag, 'sy': mag, 'sz': mag})

    def reset(self):
        if self.is_activated:
            self.stop()
        self.magnitude.empty()
Example #12
0
class ScaleLogic(object):
    def __init__(self):
        self.is_activated = False
        self.two_hands_grabbing = gestures.TwoHandsGrabbing()
        self.magnitude = MixedFilter([
            #NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05)])
        self.magnitude_origin = 0

    def frame(self, frame):
        first_hand, second_hand = frame.hands[0], frame.hands[1]
        self.two_hands_grabbing.frame((first_hand, second_hand))
        if not self.is_activated:
            if self.two_hands_grabbing.just_grabbed():
                self.start(first_hand, second_hand)
        else:
            if self.two_hands_grabbing.just_lost():
                self.stop()
            else:
                self.run(first_hand, second_hand)

    def start(self, first_hand, second_hand):
        self.is_activated = True
        send_command('object_scale_origin')
        dis = first_hand.stabilized_palm_position - second_hand.stabilized_palm_position
        self.magnitude_origin = dis.magnitude

    def stop(self):
        self.is_activated = False
        self.two_hands_grabbing.reset()

    def run(self, first_hand, second_hand):
        dis = first_hand.stabilized_palm_position - second_hand.stabilized_palm_position
        self.magnitude.add_value(dis.magnitude)
        mag = self.magnitude.value / self.magnitude_origin
        send_command('object_scale', { 'sx': mag, 'sy': mag, 'sz': mag })

    def reset(self):
        if self.is_activated:
            self.stop()
        self.magnitude.empty()
Example #13
0
    def __init__(self):
        self.grabbing_hand = gestures.GrabbingHand()
        self.is_activated = False

        # hand location
        self.loc_x_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05)])
        self.loc_y_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05)])
        self.loc_z_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05)])

        self.loc_x_origin = 0
        self.loc_y_origin = 0
        self.loc_z_origin = 0

        # hand rotation
        self.rot_x_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05) ])
        self.rot_y_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05) ])
        self.rot_z_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05) ])

        self.rot_x_origin = 0
        self.rot_y_origin = 0
        self.rot_z_origin = 0
Example #14
0
class TwoHandsGrabbing(object):
    def __init__(self):
        self.grabbing_hands = {}
        self.first_hand_closed = MixedFilter(
            [
                # NoiseFilter(2, 100, 20),
                LowpassFilter(0.1)
            ]
        )
        self.second_hand_closed = MixedFilter(
            [
                # NoiseFilter(2, 100, 20),
                LowpassFilter(0.1)
            ]
        )

    def frame(self, hands):
        first_hand, second_hand = hands

        # make sure hands are setup
        if any(hand.id not in self.grabbing_hands for hand in hands):
            self.grabbing_hands = {hand.id: GrabbingHand() for hand in hands}

        # do frames
        self.grabbing_hands[first_hand.id].frame(first_hand)
        self.grabbing_hands[second_hand.id].frame(second_hand)

        # start scaling
        self.first_hand_closed.add_value(int(self.grabbing_hands[first_hand.id].just_closed()))
        self.second_hand_closed.add_value(int(self.grabbing_hands[second_hand.id].just_closed()))

    def reset(self):
        self.first_hand_closed.empty()
        self.second_hand_closed.empty()
        self.grabbing_hands = {}

    def just_grabbed(self):
        both_closed = self.first_hand_closed.value + self.second_hand_closed.value
        return abs(both_closed - 1.7) < 0.3

    def just_lost(self):
        return any(gh.just_opened() for gh in self.grabbing_hands.itervalues())
Example #15
0
class TwoHandsGrabbing(object):
    def __init__(self):
        self.grabbing_hands = {}
        self.first_hand_closed = MixedFilter([
            #NoiseFilter(2, 100, 20),
            LowpassFilter(0.1)
        ])
        self.second_hand_closed = MixedFilter([
            #NoiseFilter(2, 100, 20),
            LowpassFilter(0.1)
        ])

    def frame(self, hands):
        first_hand, second_hand = hands

        # make sure hands are setup
        if any(hand.id not in self.grabbing_hands for hand in hands):
            self.grabbing_hands = {hand.id: GrabbingHand() for hand in hands}

        # do frames
        self.grabbing_hands[first_hand.id].frame(first_hand)
        self.grabbing_hands[second_hand.id].frame(second_hand)

        # start scaling
        self.first_hand_closed.add_value(
            int(self.grabbing_hands[first_hand.id].just_closed()))
        self.second_hand_closed.add_value(
            int(self.grabbing_hands[second_hand.id].just_closed()))

    def reset(self):
        self.first_hand_closed.empty()
        self.second_hand_closed.empty()
        self.grabbing_hands = {}

    def just_grabbed(self):
        both_closed = self.first_hand_closed.value + self.second_hand_closed.value
        return abs(both_closed - 1.7) < .3

    def just_lost(self):
        return any(gh.just_opened() for gh in self.grabbing_hands.itervalues())
Example #16
0
 def __init__(self):
     self.nb_fingers = MixedFilter([NoiseFilter(100, 0.3, 10), LowpassFilter(0.9)])
Example #17
0
class GrabLogic(object):
    def __init__(self):
        self.grabbing_hand = gestures.GrabbingHand()
        self.is_activated = False

        # hand location
        self.loc_x_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05)])
        self.loc_y_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05)])
        self.loc_z_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05)])

        self.loc_x_origin = 0
        self.loc_y_origin = 0
        self.loc_z_origin = 0

        # hand rotation
        self.rot_x_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05) ])
        self.rot_y_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05) ])
        self.rot_z_hand = MixedFilter([
            NoiseFilter(1000, 100, 20),
            LowpassFilter(0.05) ])

        self.rot_x_origin = 0
        self.rot_y_origin = 0
        self.rot_z_origin = 0

    def frame(self, frame):
        hand = frame.hands[0]
        self.grabbing_hand.frame(hand)

        if not self.is_activated and self.grabbing_hand.just_closed():
            self.start(hand)
        if self.is_activated and self.grabbing_hand.just_opened():
            self.stop()
        if self.is_activated:
            self.run(hand)

    def reset(self):
        self.grabbing_hand.reset()
        if self.is_activated:
            self.stop()

    def start(self, hand):
        self.is_activated = True

        # move origin
        pos = hand.stabilized_palm_position
        self.loc_x_origin = pos.x
        self.loc_y_origin = pos.y
        self.loc_z_origin = pos.z
        send_command('object_move_origin', {})

        # rotate origin
        self.rot_x_origin = hand.direction.pitch
        self.rot_y_origin = hand.direction.yaw
        self.rot_z_origin = hand.direction.roll
        send_command('object_rotate_origin', {})

    def stop(self):
        self.is_activated = False
        self.loc_x_hand.empty()
        self.loc_y_hand.empty()
        self.loc_z_hand.empty()
        self.rot_x_hand.empty()
        self.rot_y_hand.empty()
        self.rot_z_hand.empty()

        send_command('object_move_end', {})
        send_command('object_rotate_end', {})

    def run(self, hand):
        pos = hand.stabilized_palm_position
        self.loc_x_hand.add_value(pos.x)
        self.loc_y_hand.add_value(pos.y)
        self.loc_z_hand.add_value(pos.z)

        self.rot_x_hand.add_value(hand.direction.pitch)
        self.rot_y_hand.add_value(hand.direction.yaw)
        self.rot_z_hand.add_value(hand.direction.roll)

        # send motion
        dx = self.loc_x_hand.value - self.loc_x_origin
        dy = self.loc_y_hand.value - self.loc_y_origin
        dz = self.loc_z_hand.value - self.loc_z_origin
        send_command('object_move', { 'loc_x': dx, 'loc_y': dy, 'loc_z': dz})

        # send rotation
        rx = self.rot_x_hand.value - self.rot_x_origin
        ry = self.rot_y_hand.value - self.rot_y_origin
        rz = self.rot_z_hand.value - self.rot_z_origin
        send_command('object_rotate', { 'rot_x': rx, 'rot_y': ry, 'rot_z': rz})
Example #18
0
    def __init__(self):
        self.grabbing_hand = gestures.GrabbingHand()
        self.is_activated = False

        # hand location
        self.loc_x_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])
        self.loc_y_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])
        self.loc_z_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])

        self.loc_x_origin = 0
        self.loc_y_origin = 0
        self.loc_z_origin = 0

        # hand rotation
        self.rot_x_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])
        self.rot_y_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])
        self.rot_z_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])

        self.rot_x_origin = 0
        self.rot_y_origin = 0
        self.rot_z_origin = 0
Example #19
0
class GrabLogic(object):
    def __init__(self):
        self.grabbing_hand = gestures.GrabbingHand()
        self.is_activated = False

        # hand location
        self.loc_x_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])
        self.loc_y_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])
        self.loc_z_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])

        self.loc_x_origin = 0
        self.loc_y_origin = 0
        self.loc_z_origin = 0

        # hand rotation
        self.rot_x_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])
        self.rot_y_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])
        self.rot_z_hand = MixedFilter(
            [NoiseFilter(1000, 100, 20),
             LowpassFilter(0.05)])

        self.rot_x_origin = 0
        self.rot_y_origin = 0
        self.rot_z_origin = 0

    def frame(self, frame):
        hand = frame.hands[0]
        self.grabbing_hand.frame(hand)

        if not self.is_activated and self.grabbing_hand.just_closed():
            self.start(hand)
        if self.is_activated and self.grabbing_hand.just_opened():
            self.stop()
        if self.is_activated:
            self.run(hand)

    def reset(self):
        self.grabbing_hand.reset()
        if self.is_activated:
            self.stop()

    def start(self, hand):
        self.is_activated = True

        # move origin
        pos = hand.stabilized_palm_position
        self.loc_x_origin = pos.x
        self.loc_y_origin = pos.y
        self.loc_z_origin = pos.z
        send_command('object_move_origin', {})

        # rotate origin
        self.rot_x_origin = hand.direction.pitch
        self.rot_y_origin = hand.direction.yaw
        self.rot_z_origin = hand.direction.roll
        send_command('object_rotate_origin', {})

    def stop(self):
        self.is_activated = False
        self.loc_x_hand.empty()
        self.loc_y_hand.empty()
        self.loc_z_hand.empty()
        self.rot_x_hand.empty()
        self.rot_y_hand.empty()
        self.rot_z_hand.empty()

        send_command('object_move_end', {})
        send_command('object_rotate_end', {})

    def run(self, hand):
        pos = hand.stabilized_palm_position
        self.loc_x_hand.add_value(pos.x)
        self.loc_y_hand.add_value(pos.y)
        self.loc_z_hand.add_value(pos.z)

        self.rot_x_hand.add_value(hand.direction.pitch)
        self.rot_y_hand.add_value(hand.direction.yaw)
        self.rot_z_hand.add_value(hand.direction.roll)

        # send motion
        dx = self.loc_x_hand.value - self.loc_x_origin
        dy = self.loc_y_hand.value - self.loc_y_origin
        dz = self.loc_z_hand.value - self.loc_z_origin
        send_command('object_move', {'loc_x': dx, 'loc_y': dy, 'loc_z': dz})

        # send rotation
        rx = self.rot_x_hand.value - self.rot_x_origin
        ry = self.rot_y_hand.value - self.rot_y_origin
        rz = self.rot_z_hand.value - self.rot_z_origin
        send_command('object_rotate', {'rot_x': rx, 'rot_y': ry, 'rot_z': rz})
Example #20
0
 def __init__(self):
     self.nb_fingers = MixedFilter(
         [NoiseFilter(100, 0.3, 10),
          LowpassFilter(0.9)])