예제 #1
0
def Update():
    global detcRun
    global chosenCam
    global detcMethod
    global lastAccess
    global detcThread
    global preparedYet
    global failTimeout
    global memoryTimeout
    global keepWebcamOpen

    # TODO: Recognize multiple people?
    if MASM.hasDataCheck("FDAR_KEEPOPEN", bool):
        newKeepOpen = MASM.hasDataValue("FDAR_KEEPOPEN")
        if lastAccess:
            if keepWebcamOpen and not newKeepOpen and not Facer.camOff():
                print("Camera failed to close?")
            elif not keepWebcamOpen and newKeepOpen:
                if not Facer.camOn():
                    print("Camera failed to open")
                    MASM.sendData("FDAR_FAILURE")
                else:
                    Facer.camFrame()  # Turn on light
                    MASM.sendData("FDAR_CAMON")
        keepWebcamOpen = newKeepOpen

    if MASM.hasDataCheck("FDAR_SETTIMEOUT", int):
        if (newVal := MASM.hasDataValue("FDAR_SETTIMEOUT", 0)) > 0:
            failTimeout = newVal
예제 #2
0
def recognizeKnown():
    global threshold
    global detcMethod
    global preparedYet
    global methodSwitch
    if not preparedYet:
        print("Tried to recognize before data is prepared")
        raise DataNotPrepared
    else:
        try:
            Facer.camClearBuffer()
            frame = Facer.camFrame(minLightLevel=15)
        except Facer.LightLevelLow:
            raise
        except Exception as e:
            print(f"Capture frame exception: {e}")
            MASM.sendData("FDAR_FAILURE")
            return None
        else:
            try:
                if detcMethod == 0:
                    methodSwitch = False
                elif detcMethod == 1:
                    methodSwitch = True
                elif detcMethod == 2:
                    methodSwitch = not methodSwitch
                found, people = Facer.recognize_faces_lbph(
                    frame, threshold, methodSwitch)
            except Exception as e:
                print(f"LBPH recognizing exception: {e}")
                #MASM.sendData("FDAR_FAILURE") # Disabled cuz hitting Python's nerve or something causing exception with random number, randomly. Works despite that
                return None
            else:
                if found:
                    knownFound = []
                    for person in people:
                        if person[0] is None:
                            #print("Found someone")
                            #knownFound.append("FDAR_SOMEONE")
                            # raise the threshold slowly to recognize person eventually
                            if threshold < 0.8:
                                threshold += 0.05
                        else:
                            print(f"Found {person[0]}")
                            knownFound.append(person[0])
                            if threshold > 0.6:  # Keep threshold somewhere around where person can be detected
                                threshold -= 0.06
                    return knownFound
                else:
                    print("Found nobody")
                    return None
    MASM.sendData("FDAR_FAILURE")
    return None
예제 #3
0
    method = MASM.hasDataValue("FDAR_DETECTIONMETHOD")
    if method is not None:
        if method == "HAAR":
            detcMethod = 0
        elif method == "DNN":
            detcMethod = 1
        elif method == "BOTH":
            detcMethod = 2

    if MASM.hasDataBool("FDAR_GETCAMS"):
        if keepWebcamOpen:
            Facer.camOff()
        MASM.sendData("FDAR_CAMSLIST", Facer.getCams())
        if keepWebcamOpen:
            Facer.camOn()
            Facer.camFrame()

    if MASM.hasDataCheck("FDAR_SETCAM", int):
        chosenCam = MASM.hasDataValue("FDAR_SETCAM", 0)

    if MASM.hasDataBool("FDAR_TESTCAM"):
        try:
            if keepWebcamOpen:
                Facer.camOff()
                Facer.camOn(id=chosenCam)
                Facer.camFrame()
            else:
                Facer.camOn(id=chosenCam)
                Facer.camFrame()
                time.sleep(3)  # Yes, bad
                Facer.camOff()