stm32-fmt-code/access_control_python/main.py

38 lines
781 B
Python
Raw Normal View History

2023-09-24 18:30:29 +00:00
import cv2
import threading
import time
import face_processing as fp
2023-09-17 08:27:41 +00:00
from access_control import access_control
2023-09-24 18:30:29 +00:00
SERIAL_PORT = "COM12"
CAMERA_INDEX = 0
cam = cv2.VideoCapture(CAMERA_INDEX)
stm32 = access_control(SERIAL_PORT)
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
threading.Thread(target=read_webcam).start()
while True:
while not frame_ready:
time.sleep(1)
#Try to identify face
2023-09-28 08:17:04 +00:00
faces = fp.identify_face(img, target_condidence=0.6)
2023-09-24 18:30:29 +00:00
if(len(faces)>0):
print("Door Unlocked!, Locking in 5 seconds")
stm32.unlock_door()
time.sleep(5)
stm32.lock_door()
print("Door Locked!")