From f2fb4650f5432dacafc74c28b6650374e8d32293 Mon Sep 17 00:00:00 2001 From: LucaCavalheroAlves Date: Fri, 13 Sep 2024 13:04:50 -0300 Subject: [PATCH 1/2] feat- face recog --- __pycache__/util.cpython-39.pyc | Bin 0 -> 1857 bytes main.py | 41 +++++--------------------------- 2 files changed, 6 insertions(+), 35 deletions(-) create mode 100644 __pycache__/util.cpython-39.pyc diff --git a/__pycache__/util.cpython-39.pyc b/__pycache__/util.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e9d9f4ec766fa2b2f98a5c2d152fe1f6cee6b528 GIT binary patch literal 1857 zcmZuxOOGQp5N^BOkMvBk*|LvdShe;6pfr}Sg z2#YVFn-L5=;G_=n%}jFQ*EA1drZt_joRQ65lt;YJ8IK;5JmxV^9tU~CQ{I6&wk?Kv7y38Q%{wsI zU`pDcC7f{DvX-_X4-o>7FSAwDMxZ=7cG0LV%9%#9))a?(FbwFU-uI$D5muJP!AR9y zqxwO|F)Pk&-Y-fkPs9jrR$46^{!}tnT5Keajw?q;l}k!BpBD{x@kGdKVgbA4cH-Dr zHFiK9wKErgy|h*}gV@EVvf=7f1NDK6N>wYZ(IGlTK|J#3ehc(#u>9wvqlub}qq;0k zih3fnIw}_CXk3)yu&`D%ylCLpoEt0VM@uW~4;JSxtArhH^mIUpc>qH|7@@Czf5lz> zI_#DN&ukl##Greg-+~_-TmjG5WJOvsrNB1ueMt#04-ALL8ZU#Lp;o6Z28)*SW)SKg zNL}GWslz9U;13JWY5w)CGL%)ld4SFOX8R-%ICj6BM>}f-HJ_C6G zi|4^`NmsO`0F+`lc%T%3Mi642b?|*=ipCroq2+ju_B&RKG5AV%VUZ`(rLl5+zBNMM z#}i;!GnN&|&(QT>2}-&+XS{a{6H zXxUW+2+0LmL7`YNPM}CI^Q4X7PIy6Pfqr7yG`>n&(uQrcA6(N_Y|}R8?1HWm+qufx z1kxad*LK>pA}zh%XlHH2qfdfW^z)}J)4$?v9^DW2u{OrP(0yQpC(x0ZbdxZy->Bh2 zXrmf49Ak<3&QU#DV=~FVZ*Fc}Z`sTmb=quC4R&20Gk>T>sj5aId9LRrqA3-ZO=VnI zi^j!9X)Cy+%DAMK#&W40TNGH6rb;%BsRbTe$Z`hWV6`f^>p~S<6j}^Xqk%#gLNY=L z9}V$hz9;4*!Tlq{EiM07DRF zWS20S(jH|{t@>n-W+bC~&>6W$_2+N~G8hwou&a+?(jUX%5<8QP723zV4>|o1H!-h$ u-S9c*W7r3hSM&lPEVSB}p!Bo3;>%imfj%%ON=ZsnfR%>X-86$Ue literal 0 HcmV?d00001 diff --git a/main.py b/main.py index 8ddfaa0..a9478ca 100755 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ import face_recognition import util -from test import test + class App: @@ -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') @@ -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() @@ -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) @@ -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): From 8f821a48eaf9a94bedd622d1af65b7575c92d240 Mon Sep 17 00:00:00 2001 From: LucaCavalheroAlves Date: Fri, 20 Sep 2024 10:37:48 -0300 Subject: [PATCH 2/2] =?UTF-8?q?feat=20verifica=C3=A7=C3=A3o=20de=20usu?= =?UTF-8?q?=C3=A1rio=20previamente=20cadastrado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 31 ++++++++++++++++++++++++++----- requirements.txt | 6 +++--- requirements_windows.txt | 10 +++++----- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index a9478ca..511bdb1 100755 --- a/main.py +++ b/main.py @@ -109,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() diff --git a/requirements.txt b/requirements.txt index 637245a..ada0c20 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -opencv-python==4.6.0.66 -Pillow==9.2.0 -face_recognition==1.3.0 +opencv-python +Pillow +face_recognition diff --git a/requirements_windows.txt b/requirements_windows.txt index 821b1b3..721d356 100644 --- a/requirements_windows.txt +++ b/requirements_windows.txt @@ -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