예제 #1
0
def insertmenu(mlist,
               insertmlist,
               sortedmenukey,
               win,
               accel=None,
               imagelist=None):
    #    debug.info('[makemenu] Inserting dynamic menu...')
    #    makemenu.printmenu(insertmlist)

    keys = sortedmenukey[:]
    while len(keys) > 0:
        key = keys[0]
        if key == None:
            for order, idname, caption, kind, func, message in insertmlist[
                    key]:
                id = Id.makeid(win, idname)
                menu = makemenu.makesubmenu(insertmlist, win, idname, accel,
                                            imagelist)
                makemenu.setmenutext(win, accel)
                win.menubar.Insert(findpos(mlist, key, idname), menu, caption)
                win.menuitems[idname] = menu
            removekey(insertmlist, keys, key)
        else:
            menu = win.menuitems[key]
            for order, idname, caption, kind, func, message in insertmlist[
                    key]:
                pos = findpos(mlist, key, idname)
                if insertmlist.has_key(idname):  #submenu
                    id = Id.makeid(win, idname)
                    submenu = makemenu.makesubmenu(mlist, win, idname, accel,
                                                   imagelist)
                    menu.InsertMenu(pos, id, caption, submenu)
                    win.menuitems[idname] = submenu
                else:
                    if kind == wx.ITEM_SEPARATOR:
                        menu.InsertSeparator(pos)
                    else:
                        id = Id.makeid(win, idname)
                        mitem = wx.MenuItem(menu, id, caption, message, kind)
                        if imagelist and makemenu.disableimage == False:
                            imagename = imagelist.get(idname, '')
                            if imagename:
                                image = common.getpngimage(imagename)
                                if kind == wx.ITEM_CHECK:
                                    mitem.SetBitmaps(image)
                                else:
                                    mitem.SetBitmap(image)
                        menu.InsertItem(pos, mitem)
                        win.menuitems[idname] = mitem

                    if kind in (wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO):
                        if func:
                            try:
                                f = getattr(win, func)
                                wx.EVT_MENU(win, id, f)
                            except:
                                debug.error(
                                    "[makemenu] Can't find function [%s] in class %s"
                                    % (func, win.__class__.__name__))
            removekey(insertmlist, keys, key)
예제 #2
0
파일: makemenu.py 프로젝트: zztalker/ulipad
def bind_id_to_menu(mlist, win, pid=None):
    if pid not in mlist:
        return
    
    for m in mlist[pid]:
        order, idname, caption, kind, func, message = m
        if mlist.has_key(idname):
            id = Id.makeid(win, idname)
            bind_id_to_menu(mlist, win, idname)
        else:
            if kind == wx.ITEM_SEPARATOR:
                pass
            else:
                id = Id.makeid(win, idname)
예제 #3
0
def insertmenu(mlist, insertmlist, sortedmenukey, win, accel=None, imagelist=None):
#    debug.info('[makemenu] Inserting dynamic menu...')
#    makemenu.printmenu(insertmlist)
    
    keys = sortedmenukey[:]
    while len(keys) > 0:
        key = keys[0]
        if key == None:
            for     order, idname, caption, kind, func, message in insertmlist[key]:
                id = Id.makeid(win, idname)
                menu = makemenu.makesubmenu(insertmlist, win, idname, accel, imagelist)
                makemenu.setmenutext(win, accel)
                win.menubar.Insert(findpos(mlist, key, idname), menu, caption)
                win.menuitems[idname] = menu
            removekey(insertmlist, keys, key)
        else:
            menu = win.menuitems[key]
            for     order, idname, caption, kind, func, message in insertmlist[key]:
                pos = findpos(mlist, key, idname)
                if insertmlist.has_key(idname): #submenu
                    id = Id.makeid(win, idname)
                    submenu = makemenu.makesubmenu(mlist, win, idname, accel, imagelist)
                    menu.InsertMenu(pos, id, caption, submenu)
                    win.menuitems[idname] = submenu
                else:
                    if kind == wx.ITEM_SEPARATOR:
                        menu.InsertSeparator(pos)
                    else:
                        id = Id.makeid(win, idname)
                        mitem = wx.MenuItem(menu, id, caption, message, kind)
                        if imagelist and makemenu.disableimage == False:
                            imagename = imagelist.get(idname, '')
                            if imagename:
                                image = common.getpngimage(imagename)
                                if kind == wx.ITEM_CHECK:
                                    mitem.SetBitmaps(image)
                                else:
                                    mitem.SetBitmap(image)
                        menu.InsertItem(pos, mitem)
                        win.menuitems[idname] = mitem

                    if kind in (wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO):
                        if func:
                            try:
                                f = getattr(win, func)
                                wx.EVT_MENU(win, id, f)
                            except:
                                debug.error("[makemenu] Can't find function [%s] in class %s" % (func, win.__class__.__name__))
            removekey(insertmlist, keys, key)
예제 #4
0
파일: makemenu.py 프로젝트: zztalker/ulipad
def makesubmenu(mlist, win, pid, accel=None, imagelist=None):
    menu = wx.Menu()
    if not mlist.has_key(pid):
        return menu
    for m in mlist[pid]:
        order, idname, caption, kind, func, message = m
        if mlist.has_key(idname):
            id = Id.makeid(win, idname)
            submenu = makesubmenu(mlist, win, idname, accel, imagelist)
            menu.AppendMenu(id, caption, submenu)
            win.menuitems[idname] = submenu
        else:
            if kind == wx.ITEM_SEPARATOR:
                menu.AppendSeparator()
            else:
                id = Id.makeid(win, idname)
                if accel and accel.has_key(idname):
                    caption = caption.split('\t')[0]
                    mitem = wx.MenuItem(menu, id, caption, message, kind)
                    #mitem.SetText(caption + '\t' + accel[idname][0])
                else:
                    pos = caption.find('\t')
                    if pos > -1:
                        a, b = caption.split('\t')
                        #caption = a + '\t' + b.replace('+', ',')
                    mitem = wx.MenuItem(menu, id, caption, message, kind)
                if imagelist and disableimage == False:
                    imagename = imagelist.get(idname, '')
                    if imagename:
                        image = common.getpngimage(imagename)
                        if kind == wx.ITEM_CHECK:
                            mitem.SetBitmaps(image)
                        else:
                            mitem.SetBitmap(image)
#                else:
#                    print 'nobitmap'
#                    if wx.Platform == '__WXMSW__':
#                        mitem.SetBitmap(common.getpngimage('images/empty.gif'))
                menu.AppendItem(mitem)
                win.menuitems[idname] = mitem

            if kind in (wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO):
                if func:
                    try:
                        f = getattr(win, func)
                        wx.EVT_MENU(win, id, f)
                    except:
                        debug.error("[makemenu] Can't find function [%s] in class %s" % (func, win.__class__.__name__))
    return menu
    def determine(self,text,index):
        mem = Memory.Memory()
        id = Id.Id()
        operators=ArithmeticOp.ArithmeticOp()
        #Determine arithmetic operation
        if("AssignmentStatement.py" in inspect.stack()[1][1]):
            
            if (operators.Contains(text,index)):
                result = operators.Operate(text,index)
                mem.Store(result)
                return index
        else:
            
            if(operators.Contains(text,index)):
                result = operators.Operate(text,index)
                return result
        #Determine id
        if (id.Include(text,index)):
            return mem.mem
        #Determine literal integer
        if (isinstance(int(text[index]),int)): #Determines if value stored at text[index] is an integer. If not, the
            if("AssignmentStatement.py" in inspect.stack()[1][1]): #Prevents storing memory for anything but assignment

                mem.Store(text[index])


            elif(inspect.stack()[1][3]=='sPrint'): #This determines if the sPrint method is calling ArithmeticExpression.determine
                return int(text[index])  #If it is, it returns what is stored in the memory so it can be printed.

            elif("ArithmeticExpression.py" in inspect.stack()[1][1]):
                return int(text[index])
            index+=1
            return(index)
예제 #6
0
    def Parse(self):
        id = Id.Id()
        statement = Statement.Statement()
        index = 0
        file = open("test.lua")
        filetext = file.read()
        text = filetext.split(
        )  #Uses delimiter SPACE to separate the words into a list ; Stores in list split_text
        file.close()
        #Begins initial checks
        if (text.pop(0) != "function"):
            sys.exit("function not found, program terminated.")

        id.Include(text, 0)
        text.pop(0)

        if (text.pop(0) != '('):
            sys.exit("Left paran not found, program terminated.")

        if (text.pop(0) != ')'):
            sys.exit("Right paran not found, program terminated.")

#Ends initial checks
        while text[index] != "end":
            index = statement.determineStatement(text, index)
        return
예제 #7
0
파일: Op.py 프로젝트: aacitelli/core
    def parse(self):

        # Use one-token lookahead to determine whether it's <int>, <id>, or (<exp>)
        tokNo = t.tokenizer.get_token()
        if tokNo == t.Tokens.NUMBER.value:
            self.__int = Int.Int()
            self.__int.parse()
            self.__alternative = 1
        elif tokNo == t.Tokens.IDENTIFIER.value:
            self.__id = Id.Id()
            self.__id.parse()
            self.__alternative = 2
        elif tokNo == t.Tokens.OPEN_PAREN.value:
            t.tokenizer.skip_token()  # Consume open paren
            self.__exp = Exp.Exp()
            self.__exp.parse()
            self.__alternative = 3
            tokNo = t.tokenizer.get_token()
            t.tokenizer.skip_token()  # Consume closed parent
            if tokNo != t.Tokens.CLOSED_PAREN.value:
                print("If: Expected token {}, got token {}".format(
                    t.Tokens.CLOSED_PAREN.value, tokNo))
                return -1
            # print("Loop: Consumed `)` token.")
        else:
            print("Op: Invalid Next Token {}!".format(tokNo))
            exit(-1)
            return -1

        # Successful error code
        return 0
예제 #8
0
파일: Assign.py 프로젝트: aacitelli/core
    def parse(self):

        # Id
        self.__id = Id.Id()
        self.__id.parse()

        # `=` token
        tokNo = t.tokenizer.get_token()
        t.tokenizer.skip_token()
        if tokNo != t.Tokens.EQUALS.value:
            print("Assign: Expected token {}, got token {}".format(
                t.Tokens.EQUALS.value, tokNo))
            return -1
        # print("Assign: Consumed `=` token.")

        # Exp
        self.__exp = Exp.Exp()
        self.__exp.parse()

        # `;` token
        tokNo = t.tokenizer.get_token()
        t.tokenizer.skip_token()
        if tokNo != t.Tokens.SEMICOLON.value:
            print("Assign: Expected token {}, got token {}".format(
                t.Tokens.SEMICOLON.value, tokNo))
            return -1
        # print("Assign: Consumed `;` token.")

        # Successful error code
        return 0
예제 #9
0
def inserttoolbar(win, oldtoollist, toollist, toolbaritems):
    if len(toollist) == 0:
        return

    tl = oldtoollist[:]
    newtl = toollist[:]
    newtl.sort()
    tl.extend(newtl)
    tl.sort()

    debug.info('[insert tools] toolbar list...')
    for v in newtl:
        i = tl.index(v)
        order, name = v
        if name == '|':
            win.toolbar.InsertSeparator(i)
            debug.info('\t%d -' % order)
        else:
            style = toolbaritems[name][0]
            if style == 10:
                #custom control, so others will be a function, it'll should be defined as
                #func(mainframe, toolbar)
                func = toolbaritems[name][1]
                obj = func(win, win.toolbar)
                debug.info('\t%d %s' % (order, 'call func...' + repr(func)))
                win.toolbar.InsertControl(i, obj)
            else:
                style, idname, imagefile, shorttext, longtext, func = toolbaritems[
                    name]
                debug.info('\t%d %s' % (order, idname))
                image = common.getpngimage(imagefile)
                id = Id.makeid(win, idname)
                if style == wx.ITEM_NORMAL:
                    win.toolbar.InsertSimpleTool(i, id, image, shorttext,
                                                 longtext)
                elif style == wx.ITEM_CHECK:
                    win.toolbar.InsertTool(i,
                                           id,
                                           image,
                                           isToggle=True,
                                           shortHelpString=shorttext,
                                           longHelpString=longtext)
    #           elif style == wx.ITEM_RADIO:
    #               win.toolbar.InsertRadioTool(i, id, image, shortHelp=shorttext, longHelp=longtext)
                else:
                    raise EUnknowStyleType
                if func:
                    try:
                        f = getattr(win, func)
                        wx.EVT_TOOL(win, id, f)
                    except:
                        debug.info(
                            "[maketoolbar] Can't find function [%s] in class %s"
                            % (func, win.__class__.__name__))
    win.toolbar.Realize()
예제 #10
0
    def parse(self):
        self.id = Id.Id(self.t)
        self.id.parse()

        # If the peek token is a comma, then this is a list of identifiers
        x = int(self.t.peek())
        if x == 13:
            self.t.getToken()
            self.case = 1
            self.iList = IdList(self.t)
            self.iList.parse()
예제 #11
0
def inserttoolbar(win, oldtoollist, toollist, toolbaritems):
    if len(toollist) == 0:
        return

    tl = oldtoollist[:]
    newtl = toollist[:]
    newtl.sort()
    tl.extend(newtl)
    tl.sort()

    debug.info("[insert tools] toolbar list...")
    for v in newtl:
        i = tl.index(v)
        order, name = v
        if name == "|":
            win.toolbar.InsertSeparator(i)
            debug.info("\t%d -" % order)
        else:
            style = toolbaritems[name][0]
            if style == 10:
                # custom control, so others will be a function, it'll should be defined as
                # func(mainframe, toolbar)
                func = toolbaritems[name][1]
                obj = func(win, win.toolbar)
                debug.info("\t%d %s" % (order, "call func..." + repr(func)))
                win.toolbar.InsertControl(i, obj)
            else:
                style, idname, imagefile, shorttext, longtext, func = toolbaritems[name]
                debug.info("\t%d %s" % (order, idname))
                image = common.getpngimage(imagefile)
                id = Id.makeid(win, idname)
                if style == wx.ITEM_NORMAL:
                    win.toolbar.InsertSimpleTool(i, id, image, shorttext, longtext)
                elif style == wx.ITEM_CHECK:
                    win.toolbar.InsertTool(
                        i, id, image, isToggle=True, shortHelpString=shorttext, longHelpString=longtext
                    )
                #           elif style == wx.ITEM_RADIO:
                #               win.toolbar.InsertRadioTool(i, id, image, shortHelp=shorttext, longHelp=longtext)
                else:
                    raise EUnknowStyleType
                if func:
                    try:
                        f = getattr(win, func)
                        wx.EVT_TOOL(win, id, f)
                    except:
                        debug.info(
                            "[maketoolbar] Can't find function [%s] in class %s" % (func, win.__class__.__name__)
                        )
    win.toolbar.Realize()
예제 #12
0
def addtools(win, toolbar, toollist, toolbaritems):
    #judge image size by the first item of the toolbar item list
    imagefile = toolbaritems.values()[0][2]
    image = common.getpngimage(imagefile)
    size = wx.Size(image.GetWidth(), image.GetHeight())
    toolbar.SetToolBitmapSize(size)

    toollist.sort()
    debug.info('[addtools] toolbar list...')
    for order, name in toollist:
        if name == '|':
            toolbar.AddSeparator()
            debug.info('\t%d -' % order)
        else:
            style = toolbaritems[name][0]
            if style == 10:
                #custom control, so others will be a function, it'll should be defined as
                #func(mainframe, toolbar)
                func = toolbaritems[name][1]
                obj = func(win, toolbar)
                debug.info('\t%d %s' % (order, 'call func...' + repr(func)))
                toolbar.AddControl(obj)
            else:
                style, idname, imagefile, shorttext, longtext, func = toolbaritems[
                    name]
                debug.info('\t%d %s' % (order, idname))
                image = common.getpngimage(imagefile)
                id = Id.makeid(win, idname)
                if style == wx.ITEM_NORMAL:
                    toolbar.AddSimpleTool(id, image, shorttext, longtext)
                elif style == wx.ITEM_CHECK:
                    toolbar.AddCheckTool(id,
                                         image,
                                         shortHelp=shorttext,
                                         longHelp=longtext)
    #           elif style == wx.ITEM_RADIO:
    #               toolbar.AddRadioTool(id, image, shortHelp=shorttext, longHelp=longtext)
                else:
                    raise EUnknowStyleType
                if func:
                    try:
                        f = getattr(win, func)
                        wx.EVT_TOOL(win, id, f)
                    except:
                        error.info(
                            "[addtools] Can't find function [%s] in class %s" %
                            (func, win.__class__.__name__))
    toolbar.Realize()
예제 #13
0
def initaccelerator(win, acceleratorlist):
    ikey = 0

    accelist = []
    debug.info('[accelerator] listing ...')
    for idname, value in acceleratorlist.items():
        keys, func = value
        if not keys:
            continue
        debug.info('%s\t%s' % (keys, idname))
        f, ikey = create_key(keys)
        id = Id.makeid(win, idname)
        accelist.append((f, ikey, id))

    aTable = wx.AcceleratorTable(accelist)
    win.SetAcceleratorTable(aTable)
예제 #14
0
def initaccelerator(win, acceleratorlist):
    ikey = 0

    accelist = []
    debug.info('[accelerator] listing ...')
    for idname, value in acceleratorlist.items():
        keys, func = value
        if not keys:
            continue
        debug.info('%s\t%s' % (keys, idname))
        f, ikey = create_key(keys)
        id = Id.makeid(win, idname)
        accelist.append((f, ikey, id))

    aTable = wx.AcceleratorTable(accelist)
    win.SetAcceleratorTable(aTable)
예제 #15
0
파일: IdList.py 프로젝트: aacitelli/core
    def parse(self):

        # Id
        self.__id = Id.Id()
        self.__id.parse()

        # If next is a comma, we are in second comma
        # `,` token
        tokNo = t.tokenizer.get_token()
        if tokNo == t.Tokens.COMMA.value:
            t.tokenizer.skip_token()
            # print("IdList: Consumed `,` token.")
            self.__id_list = IdList()
            self.__id_list.parse()

        # Successful error code
        return 0
예제 #16
0
def addtools(win, toolbar, toollist, toolbaritems):
    #judge image size by the first item of the toolbar item list
    imagefile = toolbaritems.values()[0][2]
    image = common.getpngimage(imagefile)
    size = wx.Size(image.GetWidth(), image.GetHeight())
    toolbar.SetToolBitmapSize(size)

    toollist.sort()
    debug.info('[addtools] toolbar list...')
    for order, name in toollist:
        if name == '|':
            toolbar.AddSeparator()
            debug.info('\t%d -' % order)
        else:
            style = toolbaritems[name][0]
            if style == 10: 
                #custom control, so others will be a function, it'll should be defined as
                #func(mainframe, toolbar)
                func = toolbaritems[name][1]
                obj = func(win, toolbar)
                debug.info('\t%d %s' % (order, 'call func...' + repr(func)))
                toolbar.AddControl(obj)
            else:
                style, idname, imagefile, shorttext, longtext, func = toolbaritems[name]
                debug.info('\t%d %s' % (order, idname))
                image = common.getpngimage(imagefile)
                id = Id.makeid(win, idname)
                if style == wx.ITEM_NORMAL:
                    toolbar.AddSimpleTool(id, image, shorttext, longtext)
                elif style == wx.ITEM_CHECK:
                    toolbar.AddCheckTool(id, image, shortHelp=shorttext, longHelp=longtext)
    #           elif style == wx.ITEM_RADIO:
    #               toolbar.AddRadioTool(id, image, shortHelp=shorttext, longHelp=longtext)
                else:
                    raise EUnknowStyleType
                if func:
                    try:
                        f = getattr(win, func)
                        wx.EVT_TOOL(win, id, f)
                    except:
                        error.info("[addtools] Can't find function [%s] in class %s" % (func, win.__class__.__name__))
    toolbar.Realize()
예제 #17
0
파일: makemenu.py 프로젝트: zztalker/ulipad
def makemenu(win, menulist, accel=None, editoraccel=None, imagelist=None):
    menuBar = wx.MenuBar()
    win.menuitems = {}

    mlist = mergemenu(menulist)
    debug.info('[makemenu] Main Menu listing...')
    printmenu(mlist, imagelist)
    makeaccelerator(mlist, accel, editoraccel)

    a = {}
    a.update(accel)
    a.update(editoraccel)
    menuBar.Freeze()
    for m in mlist[None]:
        order, idname, caption, kind, func, message = m
        id = Id.makeid(win, idname)
        menu = makesubmenu(mlist, win, idname, a, imagelist)
        menuBar.Append(menu, caption)
        win.menuitems[idname] = menu

    menuBar.Thaw()
    return menuBar
예제 #18
0
 def parse(self):
     # Parse based on one token look ahead
     x = int(self.t.peek())
     if x == 31:
         self.i = Int.Int(self.t)
         self.i.parse()
     elif x == 32:
         self.case = 1
         self.idName = self.t.getValue()
         self.id = Id.Id(self.t)
         self.id.parse()
     elif x == 20:
         self.case = 2
         self.t.getToken()
         self.e = Exp.Exp(self.t)
         x = int(self.t.getToken())
         if x != 21:
             print "Expected end parenthesis."
             exit()
     else:
         print "Invalid op."
         exit()
예제 #19
0
    def determineStatement(self,text,index):
        if_state = IfStatement.IfStatement()
        id = Id.Id()
        print_statement = PrintStatement.PrintStatement()
        #Determines if statement
        #if (text[index]=='if'):
           #index = if_state.determine(text,index):
        #Determines assignment statement
        if(id.Include(text,index)):
            index+=1 #Allows the determine statement to determine if there is a '=' present
            assign = AssignmentStatement.AssignmentStatement()
            index = assign.determine(text,index)
            return index

        #Determines while statement
        #Determines print statement
        if (text[index] == "print"):
            index+=1
            if text[index]== "(":
                index+=1
                index = print_statement.sPrint(text,index)
                return index
            else:
                sys.exit("Left paran not found.")
def recognise():
    facecascade = cv2.CascadeClassifier('Haar/haarcascade_frontalcatface.xml')
    eye = cv2.CascadeClassifier('Haar/haarcascade_eye.xml')
    spec = cv2.CascadeClassifier('Haar/haarcascade_eye_tree_eyeglasses.xml')
    count = 0
    recognizer1 = cv2.face.createLBPHFaceRecognizer()
    recognizer2 = cv2.face.createEigenFaceRecognizer()
    recognizer1.load('trainer/trainedData1.xml')
    recognizer2.load('trainer/trainedData2.xml')
    username = "******"
    # Initialize and start the video frame capture
    cam = PiCamera()
    cam.resolution = (160, 120)
    cam.framerate = 32
    rawCapture = PiRGBArray(cam, size=(160, 120))

    # allow the camera to warmup
    time.sleep(0.1)
    lastTime = time.time() * 1000.0

    # Loop
    for frame in cam.capture_continuous(rawCapture,
                                        format="bgr",
                                        use_video_port=True):
        # Read the video frame
        image = frame.array

        # Convert the captured frame into grayscale
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        # Get all face from the video frame
        faces = facecascade.detectMultiScale(gray,
                                             scaleFactor=1.1,
                                             minNeighbors=5,
                                             minSize=(30, 30),
                                             flags=cv2.CASCADE_SCALE_IMAGE)
        print time.time() * 1000.0 - lastTime, " Found {0} faces!".format(
            len(faces))
        lastTime = time.time() * 1000.0
        # For each face in faces
        for (x, y, w, h) in faces:

            # Create rectangle around the face
            #cv2.rectangle(img, (x-20,y-20), (x+w+20,y+h+20), (0,255,0), 4)
            cv2.circle(image, (x + w / 2, y + h / 2), int((w + h) / 3),
                       (255, 255, 255), 1)
            facecrp = cv2.resize((gray[y:y + h, x:x + w]), (110, 110))
            # Recognize the face belongs to which ID
            Id, confidence = recognizer1.predict(facecrp)
            Id1, confidence1 = recognizer2.predict(facecrp)

            # Check the ID if exist
            Name = findid.ID2Name(Id, confidence)
            Name2 = findid.ID2Name(Id1, confidence1 / 100)
            print("Eigen:", Name)
            print("LBPH", Name2)
            #           print(Id1,confidence1,Name,Name2,username,count)

            if (count == 0):
                username = Name2
                count += 1
            if (count > 0 and username == Name2):
                count += 1
            if count == 10:
                break
            findid.DispID(x, y, w, h, Name, gray)
            if Name2 is not None:
                cv2.putText(image, Name2,
                            ((x + w / 2 - (len(Name2) * 7 / 2)), y - 20),
                            cv2.FONT_HERSHEY_DUPLEX, .4, [255, 255, 255])
            else:
                findid.DispID(x, y, w, h, "Face Not Recognized", gray)

        cv2.imshow('Face', image)
        rawCapture.truncate(0)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        if count == 10:
            break
    print(username)
    cv2.imwrite("tmp/face.jpg", image)
    db.fetch(username, "tmp/face.jpg")
    cam.close()
    cv2.destroyAllWindows()
    return username
예제 #21
0
from picamera.array import PiRGBArray
from picamera import PiCamera
import cv2
import numpy as np
import Id

camera = PiCamera()
camera.resolution = (160, 128)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(160, 128))
face_detector = cv2.CascadeClassifier('Haar/haarcascade_frontalcatface.xml')
eye_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye.xml')
face_id = Id.AddName()
count = 0
WHITE = [255, 255, 255]
while (count < 200):
    ret, img = camera.capture_continuous(rawCapture,
                                         format="bgr",
                                         use_video_port=True)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    if np.average(gray) > 110:
        faces = face_detector.detectMultiScale(gray, 1.3, 5)
        for (x, y, w, h) in faces:
            Face = gray[y - int(h / 2):y + int(h * 1.5),
                        x - int(x / 2):x + int(w * 1.5)]
            eyes = (Id.DetectEyes(Face))
            cv2.putText(gray, "Face Detected", (x + (w / 2), y - 5),
                        cv2.FONT_HERSHEY_DUPLEX, .4, WHITE)
            if eyes is not None:
                frame = eyes
            else:
예제 #22
0
 def getId(self):
     s = self.lex.getToken()
     if s == "" or len(s) > 1:
         raise ParserException("id expected, received " + s)
     return Id(s)
예제 #23
0
 def __init__(self, t):
     self.e = Exp.Exp(t)
     self.id = Id.Id(t)
     self.t = t
예제 #24
0
cascPath = 'Haar/haarcascade_frontalcatface.xml'

# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (160, 120)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(160, 120))

# allow the camera to warmup
time.sleep(0.1)
lastTime = time.time() * 1000.0
num = 0
id = Id.AddName()
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture,
                                       format="bgr",
                                       use_video_port=True):
    # grab the raw NumPy array representing the image, then initialize the timestamp
    # and occupied/unoccupied text
    image = frame.array
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    if (num > 200):
        break
    # Detect faces in the image
    faces = faceCascade.detectMultiScale(gray,
                                         scaleFactor=1.1,
                                         minNeighbors=5,
                                         minSize=(30, 30),