forked from datct00/Face-recognition-app-using-Streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tracking.py
78 lines (65 loc) · 2.58 KB
/
Tracking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import streamlit as st
import cv2
import face_recognition as frg
import yaml
from utils import recognize, build_dataset
# Path: code\app.py
st.set_page_config(layout="wide")
#Config
cfg = yaml.load(open('config.yaml','r'),Loader=yaml.FullLoader)
PICTURE_PROMPT = cfg['INFO']['PICTURE_PROMPT']
WEBCAM_PROMPT = cfg['INFO']['WEBCAM_PROMPT']
st.sidebar.title("Settings")
#Create a menu bar
menu = ["Picture","Webcam"]
choice = st.sidebar.selectbox("Input type",menu)
#Put slide to adjust tolerance
TOLERANCE = st.sidebar.slider("Tolerance",0.0,1.0,0.5,0.01)
st.sidebar.info("Tolerance is the threshold for face recognition. The lower the tolerance, the more strict the face recognition. The higher the tolerance, the more loose the face recognition.")
#Infomation section
st.sidebar.title("Student Information")
name_container = st.sidebar.empty()
id_container = st.sidebar.empty()
name_container.info('Name: Unnknown')
id_container.success('ID: Unknown')
if choice == "Picture":
st.title("Face Recognition App")
st.write(PICTURE_PROMPT)
uploaded_images = st.file_uploader("Upload",type=['jpg','png','jpeg'],accept_multiple_files=True)
if len(uploaded_images) != 0:
#Read uploaded image with face_recognition
for image in uploaded_images:
image = frg.load_image_file(image)
image, name, id = recognize(image,TOLERANCE)
name_container.info(f"Name: {name}")
id_container.success(f"ID: {id}")
st.image(image)
else:
st.info("Please upload an image")
elif choice == "Webcam":
st.title("Face Recognition App")
st.write(WEBCAM_PROMPT)
#Camera Settings
cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
FRAME_WINDOW = st.image([])
while True:
ret, frame = cam.read()
if not ret:
st.error("Failed to capture frame from camera")
st.info("Please turn off the other app that is using the camera and restart app")
st.stop()
image, name, id = recognize(frame,TOLERANCE)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
#Display name and ID of the person
name_container.info(f"Name: {name}")
id_container.success(f"ID: {id}")
FRAME_WINDOW.image(image)
with st.sidebar.form(key='my_form'):
st.title("Developer Section")
submit_button = st.form_submit_button(label='REBUILD DATASET')
if submit_button:
with st.spinner("Rebuilding dataset..."):
build_dataset()
st.success("Dataset has been reset")