Exemple #1
0
def lookup (points):
  strokes = moosegesture.getGesture(points)
  if len(strokes) == 0:
    if identify_hold(points):
      if len(points) > 10:
        return "long_hold"
      else: 
        return "short_hold"
    return None
  possibles = gestureMap.keys()
  gestures = moosegesture.findClosestMatchingGesture(strokes, 
    gestureMap.keys(),
    tolerance=3)

  print strokes

  if gestures == None:
    return None

  gestures = [gestureMap[x] for x in gestures]

  for g in gestures:
    print "potential", g
  
  for shape in ["updown", "triangle", "square", "leftright", "upright", \
                "upleft", "downleft", "downright"]:
    if shape in gestures:
      return shape

  return gestures[0]
    def on_button(self, pressed):
        # print(f"button:{pressed}")
        self.pressed = pressed

        if pressed:
            self.spell = None
            self.time = time.time_ns()
            self.positions = []
        else:
            # If releasing the button, get the gesture
            norm = self.min_max_normalize(self.positions)
            # print(norm)
            ms = round((time.time_ns() - self.time) / 1000)
            print(ms)
            gesture = mg.getGesture(norm)
            closest = mg.findClosestMatchingGesture(gesture,
                                                    self.gestures,
                                                    maxDifference=1)

            if closest != None:
                # Just use the first gesture in the list using the gesture key
                self.spell = self.gestures[closest[0]]
                self.vibrate(PATTERN.SHORT)
            # Print out the gesture
            print(f"{gesture}: {self.spell}")
Exemple #3
0
def gestureReco(buff1,buff2,gestures):
    pt1=np.array(buff1.allData())
    pt2=np.array(buff2.allData())
    x0=pt1[:,0]
    y0=pt1[:,1]
    x1=pt2[:,0]
    y1=pt2[:,1]
    x0=ptsPreprocess(x0)
    y0=ptsPreprocess(y0)
    x1=ptsPreprocess(x1)
    y1=ptsPreprocess(y1)
    dist=distanceVec(x0,y0,x1,y1)
    pts=dist2pts(dist)
    currgest=mg.getGesture(pts)
    currgest=[str(i) for i in currgest]
    result=mg.findClosestMatchingGesture(currgest,gestures)
    return str(result).strip('['),currgest
Exemple #4
0
    def on_button(self, pressed):
        self.pressed = pressed

        if pressed:
            self.spell = None
        else:
            # If releasing the button, get the gesture
            gesture = mg.getGesture(self.positions)
            self.positions = []
            closest = mg.findClosestMatchingGesture(gesture,
                                                    self.gestures,
                                                    maxDifference=1)

            if closest != None:
                # Just use the first gesture in the list using the gesture key
                self.spell = self.gestures[closest[0]]
                self.vibrate(PATTERN.SHORT)
            # Print out the gesture
            print("{}: {}".format(gesture, self.spell))
Exemple #5
0
def sanitize_and_notify(coord_set):
    timestamp_vals = {}
    # filter all X axis events and set their timestamps
    for _, x_event in coord_set:
        if x_event is not None:
            timestamp_vals[f'{x_event.timestamp()}'] = [x_event.value]

    # filter all Y axis events and set their timestamps
    for y_event, _ in coord_set:
        try:
            if y_event is not None:
                try:
                    timestamp_vals[f'{y_event.timestamp()}'][1] = y_event.value
                except IndexError:
                    timestamp_vals[f'{y_event.timestamp()}'].append(
                        y_event.value)
        except KeyError:
            pass

    sanitized_tuple_list = []
    for item in timestamp_vals.values():
        if len(item) == 2:
            sanitized_tuple_list.append(tuple(item))
    # ignore the first 10% events cause it's garbage sometimes
    trim_beginning_len = 0.1 * len(sanitized_tuple_list)

    detected_gesture = moosegesture.getGesture(
        sanitized_tuple_list[int(trim_beginning_len):])
    # print(f'Gesture is :- {detected_gesture}')
    closest_match = moosegesture.findClosestMatchingGesture(detected_gesture,
                                                            tuple_gesture_keys,
                                                            maxDifference=4)

    if closest_match is None:
        return None
    notify(f"Gesture Detected :- {gesture_map[str(closest_match[0])]}")
    return gesture_map[str(closest_match[0])]
Exemple #6
0
 def test_findClosest(self):
         strokes  = [DOWN, LEFT, RIGHT]
         gestures = [[DOWN, LEFT, DOWN], [DOWN, RIGHT, UPRIGHT]]
         self.assertEqual(moosegesture.findClosestMatchingGesture(strokes, gestures), ((DOWN, LEFT, DOWN),))