-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
executable file
·86 lines (65 loc) · 2.17 KB
/
util.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
79
80
81
82
83
84
85
import os
import pickle
import tkinter as tk
from tkinter import messagebox
import face_recognition
present = set()
def show_message(window, text):
label = tk.Label(window, text=text,
background="green",
foreground="white")
label.place(anchor="n", relx=.5, y=10)
label.after(3000, label.destroy)
def get_button(window, text, color, command, fg='white'):
button = tk.Button(
window,
text=text,
activebackground="black",
activeforeground="white",
fg=fg,
bg=color,
command=command,
height=2,
width=20,
font=('Helvetica bold', 20)
)
return button
def get_img_label(window):
label = tk.Label(window)
label.grid(row=0, column=0)
return label
def get_text_label(window, text):
label = tk.Label(window, text=text)
label.config(font=("sans-serif", 21), justify="left")
return label
def get_entry_text(window):
inputtxt = tk.Text(window,
height=2,
width=20, font=("Arial", 18))
return inputtxt
def msg_box(title, description):
messagebox.showinfo(title, description)
def recognize(img, db_path):
# it is assumed there will be at most 1 match in the db
embeddings_unknown = face_recognition.face_encodings(img)
if len(embeddings_unknown) == 0:
return 'no_persons_found'
else:
embeddings_unknown = embeddings_unknown[0]
db_dir = sorted(os.listdir(db_path))
match = False
j = 0
while not match and j < len(db_dir):
path_ = os.path.join(db_path, db_dir[j])
file = open(path_, 'rb')
embeddings = pickle.load(file)
match = face_recognition.compare_faces([embeddings], embeddings_unknown)[0]
j += 1
if match:
if db_dir[j - 1][:-7] in present:
return "marked"
else:
present.add(db_dir[j - 1][:-7])
return db_dir[j - 1][:-7]
else:
return 'unknown_person'