stm32-fmt-code/access_control_python/main.py

41 lines
892 B
Python

import cv2
import threading
import time
import face_processing as fp
from access_control import access_control
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
if stm32.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!")
print("DONE")