import cv2 import threading import time import face_processing as fp from access_control_mqtt import access_control from database import Database, Student, Parent from display import Display SERIAL_PORT_DISPLAY = "COM26" CAMERA_INDEX = 0 cam = cv2.VideoCapture(CAMERA_INDEX) actrl = access_control() display = Display(SERIAL_PORT_DISPLAY) db = Database() global img global frame_ready frame_ready = False def read_webcam(): global img global frame_ready while True: ret, img = cam.read() frame_ready = True ''' display.set_page("student") display.set_string("msg.txt","Door Open") ''' threading.Thread(target=read_webcam).start() while True: while not frame_ready: time.sleep(1) #Try to identify face if actrl.get_scan_state(): print("SCAN ACTIVE!") faces = fp.identify_face(img, target_condidence=0.6) ## Scan student face if(len(faces)==1): facefile = faces[0]['name'] ## File name student_info = db.get_student_info(facefile)## Check is it student? db.log_access_student(student_info) # Log student data if(student_info!=None): #is student, request another scan for parent #db.log_access_student_file() time.sleep(2) display.set_page("student") display.set_string("msg.txt","Scan parent face") parent_face = fp.identify_face(img, target_condidence=0.6) parent_info = db.get_parent_info(parent_face) #TODO Fill in student info if(parent_info != None): # Identified parent if(db.check_relationship(student_info,parent_info)): # Check if the detected parent is right for the detected student. #TODO Log Access STDw/P #TODO write parrent info to display access_control.unlock_door() # Door open display.set_string("msg.txt","Get your kid") #TODO Send timer to display time.sleep(10) #TODO Check if door can be locked # if can lock, lock #TODO If can't lock, say left open #Countdown # Activate Alarm else: display.set_page("scan") display.set_string("msg.txt","Wrong parent. \t Try Again") #TODO Try again does not try again else: display.set_page("student") display.set_string("msg.txt","Cannot find parent data. \t Try Again") else: display.set_page("student") display.set_string("msg.txt","Cannot find student data. \t Try Again") pass elif (len(faces)>1): #More than one people, error. print("more than one people. \t try again") display.set_string("msg.txt","More than one people. \t try again") time.sleep(2) pass print("DONE") else: print("Scan inactivate!!") ''' #is student, request another scan for parent parent_face = fp.identify_face(img, target_condidence=0.6) if(len(faces)==1): parent_info = db.get_parent_info(faces[0]['name']) if(parent_info!=None): if(db.check_relationship(student_info,parent_info)): #Student is under parent, open door. pass else: #Wrong Parent, retry. pass else: #Not a parent, retry pass '''