Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat verificação de usuario cadastrado #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/util.cpython-39.pyc
Binary file not shown.
72 changes: 32 additions & 40 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import face_recognition

import util
from test import test



class App:
Expand All @@ -19,8 +19,7 @@ def __init__(self):
self.login_button_main_window = util.get_button(self.main_window, 'login', 'green', self.login)
self.login_button_main_window.place(x=750, y=200)

self.logout_button_main_window = util.get_button(self.main_window, 'logout', 'red', self.logout)
self.logout_button_main_window.place(x=750, y=300)


self.register_new_user_button_main_window = util.get_button(self.main_window, 'register new user', 'gray',
self.register_new_user, fg='black')
Expand All @@ -39,7 +38,7 @@ def __init__(self):

def add_webcam(self, label):
if 'cap' not in self.__dict__:
self.cap = cv2.VideoCapture(2)
self.cap = cv2.VideoCapture(0)

self._label = label
self.process_webcam()
Expand All @@ -58,13 +57,7 @@ def process_webcam(self):

def login(self):

label = test(
image=self.most_recent_capture_arr,
model_dir='/home/phillip/Desktop/todays_tutorial/27_face_recognition_spoofing/code/face-attendance-system/Silent-Face-Anti-Spoofing/resources/anti_spoof_models',
device_id=0
)

if label == 1:


name = util.recognize(self.most_recent_capture_arr, self.db_dir)

Expand All @@ -76,31 +69,9 @@ def login(self):
f.write('{},{},in\n'.format(name, datetime.datetime.now()))
f.close()

else:
util.msg_box('Hey, you are a spoofer!', 'You are fake !')

def logout(self):


label = test(
image=self.most_recent_capture_arr,
model_dir='/home/phillip/Desktop/todays_tutorial/27_face_recognition_spoofing/code/face-attendance-system/Silent-Face-Anti-Spoofing/resources/anti_spoof_models',
device_id=0
)

if label == 1:

name = util.recognize(self.most_recent_capture_arr, self.db_dir)

if name in ['unknown_person', 'no_persons_found']:
util.msg_box('Ups...', 'Unknown user. Please register new user or try again.')
else:
util.msg_box('Hasta la vista !', 'Goodbye, {}.'.format(name))
with open(self.log_path, 'a') as f:
f.write('{},{},out\n'.format(name, datetime.datetime.now()))
f.close()

else:
util.msg_box('Hey, you are a spoofer!', 'You are fake !')



def register_new_user(self):
Expand Down Expand Up @@ -138,18 +109,39 @@ def start(self):
self.main_window.mainloop()

def accept_register_new_user(self):
name = self.entry_text_register_new_user.get(1.0, "end-1c")
# Captura a codificação facial
new_user_encodings = face_recognition.face_encodings(self.register_new_user_capture)

embeddings = face_recognition.face_encodings(self.register_new_user_capture)[0]
if not new_user_encodings:
util.msg_box('Erro!', 'Não foi possível detectar um rosto. Tente novamente.')
return

file = open(os.path.join(self.db_dir, '{}.pickle'.format(name)), 'wb')
pickle.dump(embeddings, file)
new_user_encoding = new_user_encodings[0]

util.msg_box('Success!', 'User was registered successfully !')
# Carregar todas as codificações existentes
existing_encodings = []
for filename in os.listdir(self.db_dir):
if filename.endswith('.pickle'):
with open(os.path.join(self.db_dir, filename), 'rb') as file:
existing_encodings.append(pickle.load(file))

# Verificar se a nova codificação já existe
matches = face_recognition.compare_faces(existing_encodings, new_user_encoding)

if any(matches):
util.msg_box('Erro!', 'Usuário já cadastrado. Tente registrar um rosto diferente.')
return

# Salva a nova codificação facial
name = self.entry_text_register_new_user.get(1.0, "end-1c").strip()
with open(os.path.join(self.db_dir, f'{name}.pickle'), 'wb') as file:
pickle.dump(new_user_encoding, file)

util.msg_box('Sucesso!', 'Usuário registrado com sucesso!')
self.register_new_user_window.destroy()



if __name__ == "__main__":
app = App()
app.start()
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
opencv-python==4.6.0.66
Pillow==9.2.0
face_recognition==1.3.0
opencv-python
Pillow
face_recognition
10 changes: 5 additions & 5 deletions requirements_windows.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake==3.17.2
dlib==19.18.0
opencv-python==4.6.0.66
Pillow==9.2.0
cmake
dlib
opencv-python
Pillow
face_recognition==1.3.0

#dificil funcionar