Beispiel #1
0
def velocity_histogram(frames, bins=8, range=(-1., 1.)):
    length = range[1] - range[0]
    bin_size = length / bins

    def hround(v):
        return min(bins - 1, int((v - range[0]) / bin_size))

    l = list_3d(bins)
    for frame in frames:
        for hand in frame.hands():
            for finger in hand.fingers():
                v = finger.velocity()
                vector = Leap.Vector(v.x, v.y, v.z)
                x = v.x / utils.norm(vector)
                y = v.y / utils.norm(vector)
                z = v.z / utils.norm(vector)
                l[hround(x)][hround(y)][hround(z)] += 1
    return l
Beispiel #2
0
 def _do_actions(self, frame):
     """Perform actions with frame"""
     for n, hand in enumerate(frame.hands):
         avg_pos = Leap.Vector()
         for finger in hand.fingers:
             avg_pos += finger.tip_position
         avg_pos /= len(hand.fingers)
         x_range = X_MAX - X_MIN
         try:
             action_n = int(avg_pos[0] - X_MIN) / (x_range /
                                                   len(self.actions))
         except ValueError:
             continue
         action_y = avg_pos[1] < Y_MID
         action = self.actions[action_n][action_y]
         self._deck.highlight(action_n, action_y)
         action(self._arm)(STEP)
         print action
Beispiel #3
0
    def __init__(self, callback, controller):
        super(TempoListener, self).__init__()

        self.average_velocity = Leap.Vector(0, 0, 0)
        self.angle_history = []
        self.velocity_history = []

        self.changing = False

        self.last_change_time = None
        self.bpm = 0

        self.callback = callback
        self.controller = controller

        #settings
        self.default_alpha = .3  #for the kalman filters
        self.threshold_angle = .7
        self.threshold_speed = .1
        self.threshold_count = 3
Beispiel #4
0
def average_position(vectors):
    ave_x = ave([v.x for v in vectors])
    ave_y = ave([v.y for v in vectors])
    ave_z = ave([v.z for v in vectors])
    return Leap.Vector(ave_x, ave_y, ave_z)
Beispiel #5
0
def ave_v(vectors):
    xs = [v.x for v in vectors]
    ys = [v.y for v in vectors]
    zs = [v.z for v in vectors]
    return Leap.Vector(ave(xs), ave(ys), ave(zs))
Beispiel #6
0
def add(vec1, vec2):
    return Leap.Vector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z * vec2.z)
Beispiel #7
0
def mul(vec, a):
    return Leap.Vector(vec.x * a, vec.y * a, vec.z * a)