Ejemplo n.º 1
0
class FaceCheck(Thread):
    # Initializing Lock object
    lock = Solenoid()
    # Initializing perform action variable
    perform_action = False
    # Initialize using camera variable
    using_camera = False
    # Private variable for face
    _face = True
    # Private variable of frames detected
    _frames_checked = 0
    # Private variable for face id
    _id = 0
    _counter_seconds = 5
    global threshold

    # Function to start a counter that counts to 5 1 second at a time
    def counter(self):
        c = 0
        while c < self._counter_seconds and self.perform_action is True:
            c = c + 1
            sleep(1)

    # Function to check
    def check(self):
        c = Thread(target=self.counter)
        c.daemon = True
        c.start()
        self._frames_checked = 0
        while c.is_alive():
            res = Recognition.recognize()
            if res is not None:
                self._frames_checked = self._frames_checked + 1
                print("%s, %s" % (res[0], res[1]))
                if self._id != res[0]:
                    self._face = False
                    print(self._face)
                    break
                elif self._id == res[0] and res[1] > 80:
                    self._face = False
                    print(self._face)
                    break

    # Function to start capturing from camera
    def capture_camera(self):
        CV2Video.capture()
        self.using_camera = True

    # Function to stop capturing and release camera
    def release_camera(self):
        CV2Video.release()
        self.using_camera = False

    # Function to run face check and unlock door if faces meet the criteria of true greater than 20 frames in a row
    def run(self):
        while True:
            # Firebase reference
            data = fb.get_data()
            # setting timer variable to firebase timer value
            threshold = data['doorbell']['facial_recognition']['threshold']
            print(threshold)
            # If face check is turned on and camera is off, start capturing video from camera
            if self.perform_action is True and self.using_camera is False:
                self.capture_camera()

            # If face check if off and camera instance is on, release camera
            elif self.perform_action is False and self.using_camera is True:
                self.release_camera()

            # If camera is true
            if self.using_camera is True:
                # set face recognizer values[ID, accuracy] to res
                res = Recognition.recognize()
                print(res)
                #print(threshold)
                # If res is not None and accuracy is less than threshold
                if res is not None and res[1] < threshold:
                    # Set id to res id
                    self._id = res[0]
                    # Set face to true
                    self._face = True
                    # Setup thread to run the check function
                    t = Thread(target=self.check)
                    # Start the thread
                    t.start()
                    # Join the thread to the main thread
                    t.join()
                    # Release the camera
                    self.release_camera()
                    # If face is true for 20 frames that are detected in a row
                    if self._face is True and self._frames_checked >= 20:
                        # unlock door
                        self.lock.unlock_door()
                        print(self._id)
                        print(self._face)
                        sleep(10)
Ejemplo n.º 2
0
from threading import Thread
from time import sleep

from self import self

from facial_recognition import FacialRecognition
from lock import Solenoid

fr = FacialRecognition()
lock = Solenoid()
id = 0
face = True


class facecheck:

    print("IN FACECHECK")
    id = 0

    def counter(self):
        c = 0
        while c < 3:
            c = c + 1
            sleep(1)

    def check(self):
        global face
        c = Thread(target=facecheck.counter, args=(self, ))
        c.daemon = True
        c.start()
        while c.is_alive():
Ejemplo n.º 3
0
import RPi.GPIO as GPIO
from threading import Thread
from time import sleep
from facial_recognition import FacialRecognition
from lock import Solenoid

fr = FacialRecognition()
lock = Solenoid()
id = 0
face = True


def counter():
    c = 0
    while c < 7:
        c = c + 1
        sleep(1)


def check():
    global face
    c = Thread(target=counter)
    c.daemon = True
    c.start()
    while c.is_alive():
        res = fr.recognize()
        if res is not None:
            print("%s, %s" % (id, res))
            if id != res[0]:
                face = False
                print(face)
Ejemplo n.º 4
0
    def get(self):
        # oldpos = ""
        while True:
            try:
                print("Starting the loop for checking values on Firebase")
                data = fb.get_data()
                # getting firebase values
                lock = data['doorbell']['lock']['state']
                face = data['doorbell']['face']['state']
                camera = data['doorbell']['camera']['state']
                audio = data['doorbell']['audio']['state']
                time.sleep(.5)
                print(lock)

                # checking if door has been unlockedd
                if lock == "open":
                    print("The lock has been opened")
                    Solenoid.unlock_door(Solenoid.lock)
                    readings = {'doorbell/lock/state': "closed"}
                    fb.update_data(readings)

                # take pictures for new face recognition
                if face == "new":
                    print("New face being added..")
                    nface.take_pictures()
                    print("Face Added and Trained")
                    readings = {'doorbell/face/state': "added"}
                    fb.update_data(readings)
                """ elif face == "train":
                    print ("Face being trained")
                    tface.train_faces()
                    readings = {'doorbell/face/state': "trained"}
                    fb.update_data(readings)

                if camera == "start":
                    print ("camera start")
                    #p = subprocess.call(
                     #   'gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! video/x-raw,width=640,height=480,framerate=30/1,format=I420 ! omxh264enc periodicty-idr=45 inline-header=FALSE ! h264parse ! video/x-h264,stream-format=avc,alignment=au,profile=baseline ! kvssink name=sink stream-name="test" access-key="AKIAIEKOVTSQMMS4JRTQ" secret-key="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" alsasrc device=hw:2,0 ! audioconvert ! avenc_aac ! queue ! sink.', shell=True)
                    #print(p)
                    #os.system("docker start bell")
                    #start_stream.start()
                    #time.sleep(20)
                    readings = {'doorbell/camera/state': "waiting"}
                    fb.update_data(readings)
                elif camera == "stop":
                    print ("camera stop")
                    os.system("docker stop bell")
                    readings = {'doorbell/camera/state': "waiting"}
                    fb.update_data(readings)"""

                if audio == "new":
                    fb.download_file()
                    print("new audio")
                    #file = "audio.mp3"
                    # m = alsaaudio.Mixer("PCM")
                    # current_volume = m.getvolume()  # Get the current Volume
                    # m.setvolume(75)  # Set the volume to 70%.
                    # print (current_volume)
                    #os.system("mpg123 " + file)
                    os.system("omxplayer audio.mp3")
                    readings = {'doorbell/audio/state': "waiting"}
                    fb.update_data(readings)

            except KeyboardInterrupt:
                #p.stop()
                GPIO.cleanup()
                sys.exit(0)
                #threadGet.join()
                print("Interrupted")
Ejemplo n.º 5
0
#from facial_recogniton import FacialRecognition
import sys
from self import self
from firebase import Firebase
import RPi.GPIO as GPIO
from threading import Thread
from lock import Solenoid
from new_face import new_face
import time
import os

# creating objects for other methods in seperate classes
#fr = FacialRecognition()
# tface = trainFace()
nface = new_face()
door = Solenoid()
fb = Firebase()


class listener:
    print("in listener")

    # get method
    def get(self):
        # oldpos = ""
        while True:
            try:
                print("Starting the loop for checking values on Firebase")
                data = fb.get_data()
                # getting firebase values
                lock = data['doorbell']['lock']['state']
Ejemplo n.º 6
0
import RPi.GPIO as GPIO
from threading import Thread
from time import sleep
from facial_recogniton import FacialRecognition
from lock import Solenoid

fr = FacialRecognition()
lock = Solenoid()
id = 0
face = True


def counter():
    c = 0
    while c < 3:
        c = c + 1
        sleep(1)


def check():
    global face
    c = Thread(target=counter)
    c.daemon = True
    c.start()
    while c.is_alive():
        res = fr.recognize()
        if res is not None:
            print("%s, %s" % (id, res))
            if id != res[0]:
                face = False
                print(face)
Ejemplo n.º 7
0
    def get(self):
        # oldpos = ""
        while True:
            try:
                print("Starting the loop for checking values on Firebase")
                data = fb.get_data()
                # getting firebase values
                lock = data['doorbell']['lock']['state']
                face = data['doorbell']['face']['state']
                camera = data['doorbell']['camera']['state']
                audio = data['doorbell']['audio']['state']
                time.sleep(.5)
                print(lock)

                # checking if door has been unlockedd
                if lock == "open":
                    print ("The lock has been opened")
                    Solenoid.unlock_door(Solenoid.lock)
                    readings = {'doorbell/lock/state': "closed"}
                    fb.update_data(readings)

                # take pictures for new face recognition
                if face == "new":
                    print ("New face being added..")
                    nface.take_pictures()
                    print ("Face Added and Trained")
                    readings = {'doorbell/face/state': "added"}
                    fb.update_data(readings)
                # elif face == "train":
                #    print ("Face being trained")
                #    tface.train_faces()
                #    readings = {'doorbell/face/state': "trained"}
                #    fb.update_data(readings)

                if camera == "start":
                    print ("camera start")
                    os.system("docker start youtube")
                    readings = {'doorbell/camera/state': "waiting"}
                    fb.update_data(readings)
                elif camera == "stop":
                    print ("camera stop")
                    os.system("docker stop youtube")
                    readings = {'doorbell/camera/state': "waiting"}
                    fb.update_data(readings)

                if audio == "new":
                    fb.download_file()
                    print ("new audio")
                    #file = "audio.mp3"
                    # m = alsaaudio.Mixer("PCM")
                    # current_volume = m.getvolume()  # Get the current Volume
                    # m.setvolume(75)  # Set the volume to 70%.
                    # print (current_volume)
                    #os.system("mpg123 " + file)
                    os.system("omxplayer audio.mp3")
                    readings = {'doorbell/audio/state': "waiting"}
                    fb.update_data(readings)

            except KeyboardInterrupt:
                #p.stop()
                GPIO.cleanup()
                sys.exit(0)
                #threadGet.join()
                print ("Interrupted")

    #def threads(self):
    #    print("STARTING LISTENER")
    #    threadGet = Thread(target=self.get())
    #    threadGet.start()
    #    threadGet.join()

#print("before thread")
#listener.threads(self)
# running the main
#if __name__ == '__main__':
#    print("IN MAIN")
    # setup threads
#    threadGet = Thread(target=listener.get(self))
        # start threads
#    threadGet.start()
        # join threads
#    threadGet.join()