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

REGISTERING A USER IS EASY BUT LOGIN IS NOT WORKING #3

Open
jyothindrapallikonda opened this issue Apr 2, 2023 · 6 comments
Open

Comments

@jyothindrapallikonda
Copy link

WHEN EVER I TRY TO REGISTER , IT SAYS USER IS REGISTERED SUCCESSFULLY. BUT WHEN THE SAME USER IS TRYING TO LOG IN , IT DOES NOTHING AND LEAVES THE ERROR LIKE THIS..

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\jyoth\AppData\Local\Programs\Python\Python311\Lib\tkinter_init_.py", line 1948, in call
return self.func(*args)
^^^^^^^^^^^^^^^^
File "C:\Users\jyoth\PycharmProjects\pythonProjectmain\face-attendance-system\main.py", line 61, in login
label = test(
^^^^^
TypeError: test() got an unexpected keyword argument 'image'

I TRIED SOME STACKOVERFLOW SOLUTIONS LIKE ITS THE PROBLEM WITH DLIB WHICH IS FAILING TO RECOGNIZE A IMAGE, I HAVE A VERY GOOD QUALITY CAMERA AND ITS RECOGNIZING MY FACE...I ONLY PROBLEM IS USERS REGISTERED CANNOT LOGIN.

MY CODE:

import os.path
import datetime
import pickle

import tkinter as tk
import cv2
from PIL import Image, ImageTk
import face_recognition

import util
from test import test

class App:
def init(self):
self.main_window = tk.Tk()
self.main_window.geometry("1200x520+350+100")

    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')
    self.register_new_user_button_main_window.place(x=750, y=400)

    self.webcam_label = util.get_img_label(self.main_window)
    self.webcam_label.place(x=10, y=0, width=700, height=500)

    self.add_webcam(self.webcam_label)

    self.db_dir = './db'
    if not os.path.exists(self.db_dir):
        os.mkdir(self.db_dir)

    self.log_path = './log.txt'

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

    self._label = label
    self.process_webcam()

def process_webcam(self):
    ret, frame = self.cap.read()

    self.most_recent_capture_arr = frame
    img_ = cv2.cvtColor(self.most_recent_capture_arr, cv2.COLOR_BGR2RGB)
    self.most_recent_capture_pil = Image.fromarray(img_)
    imgtk = ImageTk.PhotoImage(image=self.most_recent_capture_pil)
    self._label.imgtk = imgtk
    self._label.configure(image=imgtk)

    self._label.after(20, self.process_webcam)

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)

        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('Welcome back !', 'Welcome, {}.'.format(name))
            with open(self.log_path, 'a') as f:
                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):
    self.register_new_user_window = tk.Toplevel(self.main_window)
    self.register_new_user_window.geometry("1200x520+370+120")

    self.accept_button_register_new_user_window = util.get_button(self.register_new_user_window, 'Accept', 'green', self.accept_register_new_user)
    self.accept_button_register_new_user_window.place(x=750, y=300)

    self.try_again_button_register_new_user_window = util.get_button(self.register_new_user_window, 'Try again', 'red', self.try_again_register_new_user)
    self.try_again_button_register_new_user_window.place(x=750, y=400)

    self.capture_label = util.get_img_label(self.register_new_user_window)
    self.capture_label.place(x=10, y=0, width=700, height=500)

    self.add_img_to_label(self.capture_label)

    self.entry_text_register_new_user = util.get_entry_text(self.register_new_user_window)
    self.entry_text_register_new_user.place(x=750, y=150)

    self.text_label_register_new_user = util.get_text_label(self.register_new_user_window, 'Please, \ninput username:')
    self.text_label_register_new_user.place(x=750, y=70)

def try_again_register_new_user(self):
    self.register_new_user_window.destroy()

def add_img_to_label(self, label):
    imgtk = ImageTk.PhotoImage(image=self.most_recent_capture_pil)
    label.imgtk = imgtk
    label.configure(image=imgtk)

    self.register_new_user_capture = self.most_recent_capture_arr.copy()

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")

    embeddings = face_recognition.face_encodings(self.register_new_user_capture)[0]

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

    util.msg_box('Success!', 'User was registered successfully !')

    self.register_new_user_window.destroy()

if name == "main":
app = App()
app.start()

Screenshot 2023-04-02 124052

@ssr720
Copy link

ssr720 commented May 10, 2023

From test import test is not working is showing importerror.
16837545560449163841727942238918

@ssr720
Copy link

ssr720 commented May 10, 2023

You can also tell me in model_dir which path I have to add .
Uploading 16837546689006397058245036427676.jpg…

@thiagopassamani
Copy link

thiagopassamani commented Jul 24, 2023

PS C:\Tools\face-attendance-system-master> & C:/Users/thiago.passamani/AppData/Local/Programs/Python/Python310/python.exe c:/Tools/face-attendance-system-master/main.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\thiago.passamani\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 1921, in call
return self.func(*args)
File "c:\Tools\face-attendance-system-master\main.py", line 63, in login
label = test(
TypeError: test() got an unexpected keyword argument 'image'

@computervisioneng
Copy link
Owner

Have you added the Silent-Face-Anti-Spoofing directory to your PYTHONPATH?

@ComissarLetlev
Copy link

Have you added the Silent-Face-Anti-Spoofing directory to your PYTHONPATH?

can u pls tell how to do that

@lejustin24
Copy link

Have you added the Silent-Face-Anti-Spoofing directory to your PYTHONPATH?

can u pls tell how to do that

export PYTHONPATH="$PYTHONPATH:PATH/to/Silent-Face-Anti-Spoofing"
then source ~/.bashrc to activate it. you can also use nano ~/.bashrc then add the export line then do source ~/.bashrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants