コード例 #1
0
def unlock(controller, options):
    """TODO: Docstring for unlock.

    :controller: TODO
    :returns: TODO

    """
    mark = True
    last_frame_id = 0
    temp = []

    all_tip_position = [[], [], []]
    for index in range(3):
        for item in range(5):
            all_tip_position[index].append([])

    if not options.user_name:
        options.user_name = 'default'

    temp = io.loadmat(WINDOWS_PATH + '\\gestures\\' + options.user_name)['all']

    r = Recognizer()

    r.addTemplate(options.user_name, temp)

    temp = []
    for item in range(5):
        temp.append([])

    while True:
        current_frame = controller.frame()

        if current_frame.id == last_frame_id:
            continue

        last_frame_id = current_frame.id

        process_frame(current_frame, all_tip_position)

        hands_len = len(current_frame.hands)

        checked = check_motion(current_frame, temp)

        if checked == False and mark and hands_len:
            start_time = time.time()
            mark = False
        elif checked == False and mark == False and hands_len:
            interval = time.time() - start_time

            if interval > INTERVAL:
                if verify(r, all_tip_position, options.user_name):
                    return
        elif checked and hands_len:
            start_time = time.time()
            mark = True
コード例 #2
0
ファイル: magic_wand.py プロジェクト: mopat/A7
    def __init__(self, name):
        terminals = {
            'irX': dict(io='in'),
            'irY': dict(io='in'),
            'tupelIn': dict(io='in'),
            'onePressed': dict(io='in')
        }

        self.recognizer = Recognizer()
        self.recognizer.addTemplate('circle', circlePoints)
        self.recognizer.addTemplate('square', squarePoints)
        self.recognizer.addTemplate('triangle', trianglePoints)
        self.positions = []

        self.last_name = None
        self.last_accuracy = 0.0

        self.win2 = pg.GraphicsView()
        #self.win2.setGeometry(300, 300, 350, 100)

        self.win2.setBackgroundBrush(QtGui.QColor(255, 255, 255))
        self.win2.setWindowTitle('Paint Widget')
        self.win2.setGeometry(1200, 1000, 1200, 1000)

        self.vb = pg.ViewBox()

        self.win2.setCentralItem(self.vb)
        self.oneRel = False
        self.win2.show()
        self.count = 0

        # counter to prevent multiple execution when one button is released, because for each terminal input code is executed -> now every 4th step it will be executed
        self.exCount = 0

        Node.__init__(self, name, terminals=terminals)
コード例 #3
0
def add_password(all_tip_position, user_name):
    """TODO: Docstring for verify.
    :returns: TODO

    """
    r = Recognizer()

    temp = []

    for index in range(3):
        for item in range(5):
            temp = temp + all_tip_position[index][item]

    r.addTemplate(user_name, temp)

    # for index, tip in enumerate(all_tip_position[0]):
    # r.addTemplate(user_name + 'yz' + str(index), tip)
    # for index, tip in enumerate(all_tip_position[1]):
    # r.addTemplate(user_name + 'xz' + str(index), tip)
    # for index, tip in enumerate(all_tip_position[2]):
    # r.addTemplate(user_name + 'xy' + str(index), tip)

    return r
コード例 #4
0
    def __init__(self, parent, id, title, width, height):
        self.frame = wx.Frame.__init__(self,
                                       parent,
                                       id,
                                       title,
                                       size=wx.Size(width, height))
        self.SetMinSize((width, height))
        self.SetMaxSize((width, height))

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
        self.Bind(wx.EVT_MOTION, self.OnMouseMove)
        self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)

        self.mouseDown = False
        self.positions = []

        self.recognizer = Recognizer()
        self.recognizer.addTemplate('circle', circlePoints)
        self.recognizer.addTemplate('square', squarePoints)
        self.recognizer.addTemplate('triangle', trianglePoints)

        self.last_name = None
        self.last_accuracy = 0.0
コード例 #5
0
def check_all_file():
    """TODO: Docstring for main.

    :returns: TODO

    """
    controller = Leap.Controller()

    all_files = [
        os.path.splitext(x)[0] for x in os.listdir(WINDOWS_PATH + '\\gestures')
        if x[0] != '.'
    ]

    r = Recognizer()

    for a_file in all_files:
        add_password(r, a_file)

    return unlock(r, controller, a_file)
コード例 #6
0
   def __init__(self, parent, id, title, width, height):
      self.frame = wx.Frame.__init__(self, parent, id, title, size = wx.Size(width, height))
      self.SetMinSize((width, height))
      self.SetMaxSize((width, height))

      self.Bind(wx.EVT_PAINT, self.OnPaint)
      self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
      self.Bind(wx.EVT_MOTION, self.OnMouseMove)
      self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)

      self.mouseDown = False
      self.positions = []

      self.recognizer = Recognizer()
      self.recognizer.addTemplate('circle', circlePoints)
      self.recognizer.addTemplate('square', squarePoints)
      self.recognizer.addTemplate('triangle', trianglePoints)

      self.last_name = None
      self.last_accuracy = 0.0
コード例 #7
0
class RecognizerDemoWindow(wx.Frame):
   def __init__(self, parent, id, title, width, height):
      self.frame = wx.Frame.__init__(self, parent, id, title, size = wx.Size(width, height))
      self.SetMinSize((width, height))
      self.SetMaxSize((width, height))

      self.Bind(wx.EVT_PAINT, self.OnPaint)
      self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
      self.Bind(wx.EVT_MOTION, self.OnMouseMove)
      self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)

      self.mouseDown = False
      self.positions = []

      self.recognizer = Recognizer()
      self.recognizer.addTemplate('circle', circlePoints)
      self.recognizer.addTemplate('square', squarePoints)
      self.recognizer.addTemplate('triangle', trianglePoints)

      self.last_name = None
      self.last_accuracy = 0.0

   def OnPaint(self, event):
      dc = wx.BufferedPaintDC(self)
      dc.Clear()
      for position in self.positions:
         (x, y, type) = position

         if type == "start":
            r = 10
         elif type == "stop":
            r = 1

            points = [(p[0], p[1]) for p in self.positions]
            if len(points) > 10:
               (name, score) = self.recognizer.recognize(points)
               self.last_name = name
               self.last_accuracy = score
            else:
               self.last_name = '(Not enough points - try again!)'
               self.last_accuracy = 0.0
         else:
            r = 3

         dc.DrawCircle(x, y, r)

      dc.DrawText("$1 gesture recognizer demo", 10, 10)
      dc.DrawText("Gestures: circle, square, triangle", 20, 30)

      dc.DrawText("Last drawn gesture: %s" % self.last_name, 20, 60)
      dc.DrawText("Gesture accuracy: %2.2f%%" % (self.last_accuracy * 100), 20, 80)

   def OnMouseDown(self, event):
      self.mouseDown = True
      (x, y) = event.GetPosition()
      self.positions = [(x, y, 'start')]
      self.OnPaint(None)

   def OnMouseMove(self, event):
      if self.mouseDown:
         (x, y) = event.GetPosition()
         self.positions.append((x, y, 'move'))
         self.OnPaint(None)

   def OnMouseUp(self, event):
      self.mouseDown = False
      (x, y) = event.GetPosition()
      self.positions.append((x, y, 'stop'))
      self.OnPaint(None)
コード例 #8
0
ファイル: magic_wand.py プロジェクト: mopat/A7
class RecognizerNode(Node):
    nodeName = "Recognizer"

    def __init__(self, name):
        terminals = {
            'irX': dict(io='in'),
            'irY': dict(io='in'),
            'tupelIn': dict(io='in'),
            'onePressed': dict(io='in')
        }

        self.recognizer = Recognizer()
        self.recognizer.addTemplate('circle', circlePoints)
        self.recognizer.addTemplate('square', squarePoints)
        self.recognizer.addTemplate('triangle', trianglePoints)
        self.positions = []

        self.last_name = None
        self.last_accuracy = 0.0

        self.win2 = pg.GraphicsView()
        #self.win2.setGeometry(300, 300, 350, 100)

        self.win2.setBackgroundBrush(QtGui.QColor(255, 255, 255))
        self.win2.setWindowTitle('Paint Widget')
        self.win2.setGeometry(1200, 1000, 1200, 1000)

        self.vb = pg.ViewBox()

        self.win2.setCentralItem(self.vb)
        self.oneRel = False
        self.win2.show()
        self.count = 0

        # counter to prevent multiple execution when one button is released, because for each terminal input code is executed -> now every 4th step it will be executed
        self.exCount = 0

        Node.__init__(self, name, terminals=terminals)

    def process(self, **kwds):
        self.oneRel = kwds['onePressed']

        if(self.oneRel and self.exCount == 4):
            self.exCount = 0
        if self.oneRel:
                tupel = kwds['tupelIn']

                # porcess is executed every time an data comes in, so there's a counter which executes every 4th time
                if self.exCount == 0:
                    self.positions = self.resample(tupel)
                    points = [(p[0], p[1]) for p in self.positions]
                    if len(points) > 10:
                        (name, score) = self.recognizer.recognize(points)
                        self.last_name = name
                        self.last_accuracy = score

                        self.paintEl()
                    else:
                        self.last_name = '(Not enough points - try again!)'
                        self.last_accuracy = 0.0
                        print (self.last_name)
                self.exCount += 1

    # paint element depending on the gesture recognition
    def paintEl(self):
        print(self.last_name)

        if self.last_accuracy > 0.4:
            if self.last_name == 'circle':
                self.paintCircle()
            elif self.last_name == 'square':
                self.paintRect()
            elif self.last_name == 'triangle':
                self.paintTriangle()
        else:
            print ("Gesture accuracy was too low, try again please")

    def paintCircle(self):
        # random pos for element
        xPos = random.randint(0, 1200)
        yPos = random.randint(0, 1000)
        ellipse = QtGui.QGraphicsEllipseItem(QtCore.QRectF(xPos, yPos, 50, 50))

        ellipse.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)

        # random colors
        rc = self.randomColor()
        ellipse.setBrush(QtGui.QColor(rc[0], rc[1], rc[2]))

        self.vb.addItem(ellipse)

    def paintRect(self):
        # # random pos for element
        xPos = random.randint(0, 1200)
        yPos = random.randint(0, 1000)
        rect = QtGui.QGraphicsRectItem(QtCore.QRectF(xPos, yPos, 50, 50))

        rect.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)
        # random colors
        rc = self.randomColor()
        rect.setBrush(QtGui.QColor(rc[0], rc[1], rc[2]))

        self.vb.addItem(rect)

    def paintTriangle(self):
        # # random pos for element
        xPos = random.randint(0, 1200)
        yPos = random.randint(0, 1000)

        polygon = QtGui.QPolygonF([QtCore.QPointF(-50, 0), QtCore.QPointF(0, 50), QtCore.QPointF(50, 0)])
        polygon.translate(xPos, yPos)

        triangle = QtGui.QGraphicsPolygonItem(polygon)

        triangle.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)
        # random colors
        rc = self.randomColor()
        triangle.setBrush(QtGui.QColor(rc[0], rc[1], rc[2]))

        self.vb.addItem(triangle)

    # resample list of points to 64 point
    def resample(self, point_list, step_count=64):
        newpoints = []
        length = len(point_list)
        stepsize = length/step_count
        curpos = 0
        newpoints.append(point_list[0])
        i = 1
        while i < len(point_list):

            p1 = point_list[i-1]

            d = self.distance(p1, point_list[i])

            if curpos+d >= stepsize:
                nx = p1[0] + ((stepsize-curpos)/d)*(point_list[i][0]-p1[0])
                ny = p1[1] + ((stepsize-curpos)/d)*(point_list[i][1]-p1[1])
                newpoints.append([nx, ny])
                point_list.insert(i, [nx, ny])
                curpos = 0
            else:
                curpos += d
            i += 1
        return newpoints

    # distance between to points
    def distance(self, p1, p2):
        d = p2[0] - p1[0]
        if(d < 0):
            d *= -1

        return d

    def randomColor(self):
        return [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)]
コード例 #9
0
class RecognizerDemoWindow(wx.Frame):
    def __init__(self, parent, id, title, width, height):
        self.frame = wx.Frame.__init__(self,
                                       parent,
                                       id,
                                       title,
                                       size=wx.Size(width, height))
        self.SetMinSize((width, height))
        self.SetMaxSize((width, height))

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
        self.Bind(wx.EVT_MOTION, self.OnMouseMove)
        self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)

        self.mouseDown = False
        self.positions = []

        self.recognizer = Recognizer()
        self.recognizer.addTemplate('circle', circlePoints)
        self.recognizer.addTemplate('square', squarePoints)
        self.recognizer.addTemplate('triangle', trianglePoints)

        self.last_name = None
        self.last_accuracy = 0.0

    def OnPaint(self, event):
        dc = wx.BufferedPaintDC(self)
        dc.Clear()
        for position in self.positions:
            (x, y, type) = position

            if type == "start":
                r = 10
            elif type == "stop":
                r = 1

                points = [(p[0], p[1]) for p in self.positions]
                if len(points) > 10:
                    (name, score) = self.recognizer.recognize(points)
                    self.last_name = name
                    self.last_accuracy = score
                else:
                    self.last_name = '(Not enough points - try again!)'
                    self.last_accuracy = 0.0
            else:
                r = 3

            dc.DrawCircle(x, y, r)

        dc.DrawText("$1 gesture recognizer demo", 10, 10)
        dc.DrawText("Gestures: circle, square, triangle", 20, 30)

        dc.DrawText("Last drawn gesture: %s" % self.last_name, 20, 60)
        dc.DrawText("Gesture accuracy: %2.2f%%" % (self.last_accuracy * 100),
                    20, 80)

    def OnMouseDown(self, event):
        self.mouseDown = True
        (x, y) = event.GetPosition()
        self.positions = [(x, y, 'start')]
        self.OnPaint(None)

    def OnMouseMove(self, event):
        if self.mouseDown:
            (x, y) = event.GetPosition()
            self.positions.append((x, y, 'move'))
            self.OnPaint(None)

    def OnMouseUp(self, event):
        self.mouseDown = False
        (x, y) = event.GetPosition()
        self.positions.append((x, y, 'stop'))
        self.OnPaint(None)