From 4c06ea5b600650d0fe46ac1646228ed93b319e40 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 6 Nov 2023 16:10:46 +0700 Subject: [PATCH] restructured main --- .../__pycache__/espmega_mqtt.cpython-311.pyc | Bin 0 -> 3230 bytes access_control_python/access_control_mqtt.py | 27 ++++------ access_control_python/database.py | 2 +- access_control_python/main.py | 50 +++++++++++++----- 4 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 access_control_python/__pycache__/espmega_mqtt.cpython-311.pyc diff --git a/access_control_python/__pycache__/espmega_mqtt.cpython-311.pyc b/access_control_python/__pycache__/espmega_mqtt.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4520db28cbc4ca20339652253949292717019d16 GIT binary patch literal 3230 zcmb6bOKcNIboOVj9Va2d5hNshN>DKpF_3^-D9}QpfC}LgDySQ@+IZGvsl97v*PyIY zDTh=-DhDbdfz(DyB}l30flF1S_CTdpLRAmzXeFYRIQ5j9D|+J6zL~Yxb^r;+<2UcU znR)Z}{bs&zZH*&nKQA8Bei0G+n-aAKG;7cI!*Cm6gt(02uq7RLJ!~{v`hqZ<0utbq2!p8*!}*Vf!+Jw8`w3lXP*;G=hUobWmO|vUCxGR zm3Te}$Ze#d42MyM{{#-d#9`i%5XuOecp1i^X%Q@Z04VOjkvTCF#hqBzWE|6CIIhXL z2yU5^GI7ew@i+l1T5#(e$|P`GqZHf@RBKIUPQ+_qWgC`2{k49}$oT1#+9mbmnRDj| z{koMk0DQ4<#kTzj(d-g2#Za%PYc8gB+& z4)Fyl>!oJPbru$|_@lH4>mGz_In*R0v{-!?LUy7~eS>ghew9W{M$IQp@|5uO8MF|q zOQ~avfIbMxRobwy3n#0{>Kzz?{i9=kyf|G8mK5j5vUy!IY(>ZVXQ0{&^?pk5#VOOW zeX(c~+mC&&X+<@!U)3BrtsBLXo!**i@#UgAWd>e5%4CoT?DeBr(=fCw`0~ivQy-6< z^gLTa4h-*~7}f0w%PtJ=*_kWYJF_O%Ce$n>gQb8bHZk)`aoV0T zjS0;v79j8xs`Ef`+LskYH*{N3oMb~x4%E2RQPx)gX3?``@2yk!^KSA$IeEZK9=I;v zh%L*B8?mQy_mbQ_fA#**qjy}nyDT5{SFq>_T+_D9np9oCC6Ec*0}R;8qtU7Kfpj zw~!pENw&j$fK!C#3~nxfP$Gi}cBFLiS|RO-+ji~2PCRXCb~-QwZyLT}=5kdgGfPUW z#$~ZInb)l;k_3Hy!LkX=^Z-saQLveUEdVTPh|SQ*20;ASHKN;^0tY%>jZqS^+vpw} zz$|JEiHzIxA@uvXU`d}4fg#p{-o=-%jtr?pqdd9 zL{qVX^-H>~=AHG8c4(aGfGrlS=3t8UwO;$?g-)-%-2ChCh9b08h?$<6!R z9@-z4!t93v0G)lb9|`KKAFbB8rYxng&#bTpYy(yh-X=>i=fL*nj3L?Pe5%W{8*Y`x zTyNeFZvv3nxVBNJ=Cxn)^>AvQ`9fT!MR;4TS|`m&P?>10Vr@obZx6_Fmg(ThX!X8X zp_WQTeaSY9de)D#yTH1p+qHDo4ciy;n&C%_>U7>zF`>RnMS_6d3Ais}6>g9LK(5?FDLeUiTxEM#CAOE zNZveu>*Bq^d(L-qnj?*WHPJ z+g?s?_mbPMk1Y46t`B>OzB`lU#1@zJN)&`L$tjHDgULo1Q|KG{wN*EKWL4~Quf9ZVuigU+ bool: - pass - + return self.plc.read_digital(0) def get_scan_state(self) -> bool: - pass - + return self.plc.read_digital(1) def lock_door(self): - pass - + self.plc.write_pwm(1,1,4095) def unlock_door(self): - pass + self.plc.write_pwm(1,0,4095) \ No newline at end of file diff --git a/access_control_python/database.py b/access_control_python/database.py index 58f52d2..6ed8620 100644 --- a/access_control_python/database.py +++ b/access_control_python/database.py @@ -20,7 +20,7 @@ class Student(Person): class Parent(Person): pass -class database: +class Database: db = None cursor = None def __init__(self) -> None: diff --git a/access_control_python/main.py b/access_control_python/main.py index c5eae93..4675bab 100644 --- a/access_control_python/main.py +++ b/access_control_python/main.py @@ -2,17 +2,17 @@ import cv2 import threading import time import face_processing as fp -from access_control import access_control -from database import database, Student, Parent -from displ +from access_control_mqtt import access_control +from database import Database, Student, Parent +from display import Display -SERIAL_PORT_STM32 = "COM12" SERIAL_PORT_DISPLAY = "COM15" CAMERA_INDEX = 0 cam = cv2.VideoCapture(CAMERA_INDEX) -stm32 = access_control(SERIAL_PORT_STM32) -display = +actrl = access_control() +display = Display(SERIAL_PORT_DISPLAY) +db = Database() global img global frame_ready @@ -32,13 +32,37 @@ while True: time.sleep(1) #Try to identify face - if stm32.get_scan_state(): + if actrl.get_scan_state(): print("SCAN ACTIVE!") faces = fp.identify_face(img, target_condidence=0.6) - if(len(faces)>0): - print("Door Unlocked!, Locking in 5 seconds") - stm32.unlock_door() - time.sleep(5) - stm32.lock_door() - print("Door Locked!") + if(len(faces)==1): + facefile = faces[0] + parent_info = db.get_parent_info_file(facefile) + if(parent_info!=None): + pass + #Open Door for parent + else: + student_info = db.get_student_info(facefile) + if(student_info!=None): + #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]) + 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 + + elif (len(faces)>1): + #More than one people, error. + pass + else: + #No one detected + pass print("DONE")