コード例 #1
0
ファイル: barcode_scanner.py プロジェクト: unix0r/FACEID
def findQR(pathToImage):
    if (pathToImage == "ERROR"):
        logger.error("Image not found! " + pathToImage)
        return False
    isQR = False
    qrkey = ""
    logger.debug("Checking QR Codes in " + pathToImage)
    img_original = cv2.imread(pathToImage)

    image = upscale(img_original, 3.0)
    barcodes = pyzbar.decode(image)

    if len(barcodes) == 0:
        image = greyscale(image, 65)
        barcodes = pyzbar.decode(image)

    if len(barcodes) == 0:
        image = upscale(img_original, 2.0)
        barcodes = pyzbar.decode(image)

    if len(barcodes) == 0:
        image = greyscale(image, 55)
        barcodes = pyzbar.decode(image)

    # loop over the detected barcodes
    for barcode in barcodes:
        barcodeData = barcode.data.decode("utf-8")
        logger.debug("QR-Code found: " + barcodeData)
        isQR = True
        qrkey = barcodeData
    if not (isQR):
        logger.info("No QR-Code found")
    result = (isQR, qrkey)
    return result
コード例 #2
0
ファイル: FaceML.py プロジェクト: unix0r/FACEID
 def check_face(self, image):
     unknown_face_encoding = []
     time1 = datetime.now()
     logger.info("Checking unknown face")
     logger.warn(image)
     faces = []
     try:
         unknown_image = face_recognition.load_image_file(image)
         unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]
     except IndexError:
         logger.error("No faces found in " + self.path + image)
         return faces
     except IOError:
         logger.error("Cant open the unkown face file")
         return faces
     logger.debug("Comparing the known faces with the unkown picture")
     results = face_recognition.compare_faces(self.known_faces, unknown_face_encoding)
     index = 0
     for result in results:
         if result:
             logger.info("Face found in : " + self.filelist[index])
             faces.append(self.filelist[index])
         index += 1
     logger.debug("Processed Faces in " + str(datetime.now() - time1) + " seconds")
     logger.debug("Found known Face? : " + str((len(faces) != 0)))
     return faces
コード例 #3
0
ファイル: FaceML.py プロジェクト: unix0r/FACEID
 def load_known_faces(self):
     self.known_faces = []
     self.filelist = []
     time1 = datetime.now()
     if not os.path.exists(self.path):
         logger.error("Path not found_ " + self.path)
     logger.info("Loading known faces")
     for face in os.listdir(self.path):
         logger.debug("Loading face " + face)
         if face.endswith(".jpg"):
             face_image = face_recognition.load_image_file(self.path + face)
             logger.debug("Checking File for faces: " + self.path + face)
             self.filelist.append(self.path + face)
             try:
                 encodings = face_recognition.face_encodings(face_image)
                 for face_encode in encodings:
                     self.known_faces.append(face_encode)
             except IndexError:
                 logger.error("No faces found in " + face)
                 # sendMail("No Face found in file", "self.path + face")
             except IOError:
                 logger.error("Cant open the face file " + face)
                 # sendMail("No Face found in file", "self.path + face")
     logger.info("Loaded " + str(len(self.known_faces)) + " faces in " + str(
         datetime.now() - time1) + " seconds")
コード例 #4
0
ファイル: FaceML.py プロジェクト: unix0r/FACEID
 def load_new_face(self, image):
     time1 = datetime.now()
     logger.info("Loading the new face")
     face_image = face_recognition.load_image_file(image)
     try:
         encodings = face_recognition.face_encodings(face_image)
         for face_encode in encodings:
             self.known_faces.append(face_encode)
         self.filelist.append(image)
     except IndexError:
         logger.error("No faces found in " + image)
         # sendMail("No Face found in file", "self.path + face")
     except IOError:
         logger.error("Cant open the face file " + image)
         # sendMail("No Face found in file", "self.path + face")
     logger.info("Loaded all " + str(len(self.known_faces)) + " faces in " + str(
         datetime.now() - time1) + " seconds")
コード例 #5
0
def waitForEventAndDownloadImage():
    # bind socket
    udp_address = config.get("doorbird", "udp_ip_address")
    udp_port = config.get("doorbird", "udp_port")
    server_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    server_sock.bind((udp_address, int(udp_port)))
    server_sock.settimeout(int(config.get("doorbird", "keep_alive_timeout")))
    logger.info("UDP service started on address: {} and port: {}".format(
        udp_address, udp_port))
    old_message = ""
    old_event = ""

    while True:

        try:
            data = server_sock.recvfrom(1024)
        except:
            # Timeout: No Keep Alive Packets
            sendMail(
                "No KeepAlive Pakcets from Doorbird! Check your Connection")
            logger.error(
                "No KeepAlive Pakcets from Doorbird! Check your Connection")
            continue

        try:
            #read received udp data
            message = data[0].decode()

            if message != old_message:
                logger.debug("Keep-alive msg: {}".format(message))

            old_message = message

        except:
            hex_bytes = binascii.hexlify(data[0])
            event = hex_bytes.decode("ascii")

            if event != old_event:
                logger.info("Message: An event has occured!")
                old_event = event
                return downloadImage()
            old_event = event
コード例 #6
0
def main():
    # Login for Events
    logger.info("FaceID by HFU v" + version)
    failed_access = 0
    # init
    ml = FaceML()

    # read qr-codes for registration and deregistration from config
    qr_register = Configurator.get("machine_learning", "qr_register_key")
    qr_unregister = Configurator.get("machine_learning", "qr_unregister_key")

    while True:
        # wait for doorbird event
        image = waitForEventAndDownloadImage()

        # get QR-code from image
        qrtuple = findQR(image)

        if image == "ERROR":
            logger.error("No Image was downloaded from the Doorbird")
            continue

        if qrtuple[0]:
            # check if qr-code from image equals register code
            if qrtuple[1] == qr_register:
                # Danalock.open()
                logger.info('Register face')
                currentdate = datetime.datetime.now().timestamp()
                final = Configurator.get("data", "data_path_known_faces")
                file_path = final + str(currentdate) + '.jpg'

                # crop face from image
                if crop(image, file_path):
                    ml.load_new_face(file_path)
                    sendMail("Add Known Face", [image])
                    openDoor()
                    failed_access = 0
                else:
                    logger.error("No Face found in registering image " + image)
                # ml.load_known_faces()
            # check if qr-code from image equals deregistration code
            elif qrtuple[1] == qr_unregister:
                logger.info('Unregister face')
                results = ml.check_face(image)
                for result in results:
                    if result:
                        # find face in known faces and delete it
                        sendMail("Remove known face!", [result])
                        os.remove(result)
                        ml.load_known_faces()
                    else:
                        sendMail(
                            "Wanted to remove a known face, but could not find the regarding face!",
                            image)

        else:
            person_known = ml.check_face(image)
            if person_known:
                # open door
                logger.info("Open the door for authorised person...")
                openDoor()
                failed_access = 0
            else:
                # do not open door
                logger.info("No access!")
                failed_access += 1
                if failed_access > int(
                        Configurator.get("general",
                                         "max_num_of_failed_access")):
                    sendMail("5 failed attempts to access", image)
                    lockDoor()