From 0e6a41d6e511cea4aee0eea8d8b6f3c506d2fc42 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 13 Nov 2023 19:12:30 +0700 Subject: [PATCH] a --- .../access_control_mqtt.cpython-311.pyc | Bin 0 -> 2057 bytes .../__pycache__/database.cpython-311.pyc | Bin 0 -> 7258 bytes .../__pycache__/display.cpython-311.pyc | Bin 0 -> 1905 bytes access_control_python/access_control_mqtt.py | 2 +- access_control_python/database.py | 8 +- access_control_python/display.py | 1 + access_control_python/main.py | 78 ++++++++++++++---- access_control_python/test.py | 25 ++++++ 8 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 access_control_python/__pycache__/access_control_mqtt.cpython-311.pyc create mode 100644 access_control_python/__pycache__/database.cpython-311.pyc create mode 100644 access_control_python/__pycache__/display.cpython-311.pyc create mode 100644 access_control_python/test.py diff --git a/access_control_python/__pycache__/access_control_mqtt.cpython-311.pyc b/access_control_python/__pycache__/access_control_mqtt.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d6d3dc35da6c31a804ad5cacf1b5ea35481b5ab3 GIT binary patch literal 2057 zcmcIl&ubGw6rS1L#7&zTwNkbIKqOKlDySeLwxCq%#bVJ@EDUjHQlq=sI6I}b^w2{O z9(oa!_SjRU6#tjD6j~NMdFm|^Pa^1hv)#2xN)Xh^?w2?3&71eWd2e?=_VjcS7(YHe z6!#25zThMt)}GL~4Z>%CU$T5USC8LLz)im{m!&3@NnLkeOA#{lNY=iYPg2Hy|9wHE9hJNwpZ zfR;2d#l@QG5D1H8mb}CzdMqc*Vh#Rt$_;L=fX^EG>49Yj?$)TpgWE;F-Jdx^Rt;%` z9A>6uMG01$@?-|)(P_wTG}&%t;)P;TJdmCl(UV6Yh&+nWN+z?HbGbZovZXkQ1zF4E2$*b`mO@R+YE#m9 zuDT|-K=`wotiYMCCG~<@7*Vou1+r3L~|(VdnwOjD!$y^71k=5y^BgUt!mJ2t z9(?l{zSpAG{eLKLQgZ~0ep_~N( literal 0 HcmV?d00001 diff --git a/access_control_python/__pycache__/database.cpython-311.pyc b/access_control_python/__pycache__/database.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..664bef436444ed4a6df336270be10016c2b1e4f9 GIT binary patch literal 7258 zcmeHMU2GHC6`nua<2a6Eha?2b)|)K}-X-n^C_l@xf{>78NlYMNk=#g*@l3#rf5M#! zOWaV*iid24RJ5W3wTqO8Ee(ZAJoF(Ct;AEcj|obJH4+k1pLh!j>O-D-&Yd66IL@-0 zg}2_=XU@I%+@HDUJKw#&`HSCQ!$9hsAClYa80J5iF_YU+R{jObZAM}wHp67uILD&S zW%#TR7eMFZE=h>HC0E=d3mntSNbc*5DK68kQnhdS&q*54G^s zQ-!V9u&n`G-)n4Z==il@>35DF_etz96RCTFL&PGi=9Q9aGL=axO2OZGU{|zr@BZkA z(OtU_Xrd&ma!Sn;tv+`keyJxL-*a~f)#mQvGsNvH&RSP5%$y_e4Ce?I4r+^KwsN_Dgg415z*Zt9G zZ(1Ey)a>qE9phQGBbArr(PSzmD@r1jGzNlZ+s=kvKyT%@x}MUGBP5f8McLIg$G z1EOgAdoKEly~W;Zy`>s|vA@`Vt-s{2FAfw3t__p|p<=8Uy9VE4j5L_tI2MzIQcNp= zLfc|er*WERSe=yQoEp2&lUgt!eiUd*LMUjTn^0>qMF5l)6y-@i7sO(>Zi{9=Vtn^d zlHl;98N06-atoHBptIPFIjUiiV+;WbFs=L*L>Vv=8|UFGNDUHyUBFkT~!dJx7A!FVCi8|eCP(!_292Qke}WEIevG9895giL|au<}O`w;9z|_qnC3=Ieuv ziY<(!BAkpQu@AX>VE4eXon{g)vv!*K+|p-lJ(%?j<75tKYgtJQ#2O#deB;TKoX{gY zB51<-yrOEtq#_edoB%TTB2Oe>0ONHd9tfR_8O;M>kpoW9guWBQBbsn}xaX864jmaD zK6Bz!x5i0lHFs(fqL=`)2#TB;SMa^V1Tl$mo6e=xM4}Kh*D-1qAxMl^dKPND^}(O_ z{7w32-*?%C(C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HcmV?d00001 diff --git a/access_control_python/access_control_mqtt.py b/access_control_python/access_control_mqtt.py index 7bcd728..2287ef8 100644 --- a/access_control_python/access_control_mqtt.py +++ b/access_control_python/access_control_mqtt.py @@ -1,7 +1,7 @@ from espmega_mqtt import ESPMegaMQTT from time import sleep -class ac: +class access_control: def __init__(self): self.plc = ESPMegaMQTT() pass diff --git a/access_control_python/database.py b/access_control_python/database.py index 6ed8620..9d886d2 100644 --- a/access_control_python/database.py +++ b/access_control_python/database.py @@ -59,7 +59,7 @@ class Database: statement = f'INSERT INTO face_detect.`access-log` (id, student_id, parent_id, `timestamp`) VALUES(NULL, NULL, (SELECT id FROM parents WHERE parents.imagefile = "{parent_filename}"), NULL)' self.cursor.execute(statement) self.db.commit() - def log_access_student(self, student: Student, parent: Parent): + def log_access_student_with_parent(self, student: Student, parent: Parent): statement = f'INSERT INTO face_detect.`access-log` (id, student_id, parent_id, `timestamp`) VALUES(NULL, {student.id}, {parent.id}, NULL)' self.cursor.execute(statement) self.db.commit() @@ -67,5 +67,11 @@ class Database: statement = f'INSERT INTO face_detect.`access-log` (id, student_id, parent_id, `timestamp`) VALUES(NULL, NULL, {parent.id}, NULL)' self.cursor.execute(statement) self.db.commit() + def log_access_student(self, parent: Parent): + statement = f'INSERT INTO face_detect.`access-log` (id, student_id, parent_id, `timestamp`) VALUES(NULL, {student.id}, NULL, NULL)' + self.cursor.execute(statement) + self.db.commit() + + def fetch_log() -> list: pass diff --git a/access_control_python/display.py b/access_control_python/display.py index 82b4520..cd2abca 100644 --- a/access_control_python/display.py +++ b/access_control_python/display.py @@ -9,6 +9,7 @@ class Display: def set_string(self, field, text): command = f'{field}="{text}"'.encode("ascii") self.serial_adapter.write(command) + self.send_stop_bit() def send_stop_bit(self): self.serial_adapter.write(0xFF) self.serial_adapter.write(0xFF) diff --git a/access_control_python/main.py b/access_control_python/main.py index 4675bab..79acb00 100644 --- a/access_control_python/main.py +++ b/access_control_python/main.py @@ -6,7 +6,7 @@ from access_control_mqtt import access_control from database import Database, Student, Parent from display import Display -SERIAL_PORT_DISPLAY = "COM15" +SERIAL_PORT_DISPLAY = "COM26" CAMERA_INDEX = 0 cam = cv2.VideoCapture(CAMERA_INDEX) @@ -25,6 +25,11 @@ def read_webcam(): 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: @@ -34,20 +39,64 @@ while True: #Try to identify face if actrl.get_scan_state(): print("SCAN ACTIVE!") - faces = fp.identify_face(img, target_condidence=0.6) + faces = fp.identify_face(img, target_condidence=0.6) ## Scan student face if(len(faces)==1): - facefile = faces[0] - parent_info = db.get_parent_info_file(facefile) - if(parent_info!=None): - pass - #Open Door for parent + 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 + db.log_access_parent(parent_info) # Log student data + if(parent_info != None): # Identified parent + print(parent_info) + if(db.check_relationship(student_info,parent_info)): # Check if the detected parent is right for the detected student. + #TODO Log Access + display.set_page("Parent") + access_control.unlock_door() # Door open + time.sleep(10) + #display.set_string("msg.txt","Get your kid") + else: + access_control.lock_door() # Lock Door + display.set_page("Scan") + display.set_string("msg.txt","Wrong student. \t Try Again") + else: + display.set_page("student") + display.set_string("msg.txt","Cannot find parent data. \t Try Again") else: - student_info = db.get_student_info(facefile) - if(student_info!=None): + 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_page("Scan") + display.set_string("msg.txt","More than one people. \t try again") + time.sleep(2) + display.set_page("Scan") + pass + else: + #No one detected + print("No one detected \t try again")\ + display.set_page("Scan") + 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]) + 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. @@ -58,11 +107,4 @@ while True: else: #Not a parent, retry pass - - elif (len(faces)>1): - #More than one people, error. - pass - else: - #No one detected - pass - print("DONE") +''' \ No newline at end of file diff --git a/access_control_python/test.py b/access_control_python/test.py new file mode 100644 index 0000000..84a5814 --- /dev/null +++ b/access_control_python/test.py @@ -0,0 +1,25 @@ +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 +from espmega_mqtt import ESPMegaMQTT +#SERIAL_PORT_DISPLAY = "COM26" +CAMERA_INDEX = 0 + +#actrl = access_control() +#display = Display(SERIAL_PORT_DISPLAY) +db = Database() + +plc = ESPMegaMQTT() + + +while True: + for i in range(8,16): + plc.write_pwm(i, 0, 4095) + time.sleep(1) + for i in range(8,16): + plc.write_pwm(i, 1, 4095) + time.sleep(1) +