├── setup.txt ├── commit_001.csv ├── commit_002.csv ├── commit_003.csv ├── commit_004.csv ├── commit_005.csv ├── commit_006.csv ├── commit_007.csv ├── commit_008.csv ├── commit_009.csv ├── commit_010.csv ├── commit_011.csv ├── commit_012.csv ├── commit_013.csv ├── commit_014.csv ├── commit_015.csv ├── commit_016.csv ├── commit_017.csv ├── commit_018.csv ├── commit_019.csv ├── commit_020.csv ├── commit_021.csv ├── commit_022.csv ├── commit_023.csv ├── commit_024.csv ├── commit_025.csv ├── commit_026.csv ├── commit_027.csv ├── commit_028.csv ├── commit_029.csv ├── commit_030.csv ├── commit_031.csv ├── commit_032.csv ├── commit_033.csv ├── commit_034.csv ├── commit_035.csv ├── commit_036.csv ├── commit_037.csv ├── commit_038.csv ├── commit_039.csv ├── commit_040.csv ├── commit_041.csv ├── commit_042.csv ├── commit_043.csv ├── commit_044.csv ├── commit_045.csv ├── commit_046.csv ├── commit_047.csv ├── commit_048.csv ├── commit_049.csv ├── commit_050.csv ├── commit_051.csv ├── commit_052.csv ├── commit_053.csv ├── commit_054.csv ├── commit_055.csv ├── commit_056.csv ├── commit_057.csv ├── commit_058.csv ├── commit_059.csv ├── commit_060.csv ├── commit_061.csv ├── commit_062.csv ├── commit_063.csv ├── commit_064.csv ├── commit_065.csv ├── commit_066.csv ├── commit_067.csv ├── commit_068.csv ├── commit_069.csv ├── commit_070.csv ├── commit_071.csv ├── commit_072.csv ├── commit_073.csv ├── commit_074.csv ├── commit_075.csv ├── commit_076.csv ├── commit_077.csv ├── commit_078.csv ├── commit_079.csv ├── commit_080.csv ├── commit_081.csv ├── commit_082.csv ├── commit_083.csv ├── commit_084.csv ├── commit_085.csv ├── commit_086.csv ├── commit_087.csv ├── commit_088.csv ├── commit_089.csv ├── commit_090.csv ├── commit_091.csv ├── commit_092.csv ├── commit_093.csv ├── commit_094.csv ├── commit_095.csv ├── commit_096.csv ├── commit_097.csv ├── commit_098.csv ├── commit_099.csv ├── commit_100.csv ├── windows_setup.txt ├── README.md ├── util.py └── main.py /setup.txt: -------------------------------------------------------------------------------- 1 | opencv-python==4.6.0.66 2 | Pillow==9.2.0 3 | face_recognition==1.3.0 4 | -------------------------------------------------------------------------------- /commit_001.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 1: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_002.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 2: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_003.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 3: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_004.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 4: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_005.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 5: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_006.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 6: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_007.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 7: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_008.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 8: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_009.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 9: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_010.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 10: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_011.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 11: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_012.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 12: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_013.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 13: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_014.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 14: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_015.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 15: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_016.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 16: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_017.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 17: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_018.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 18: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_019.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 19: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_020.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 20: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_021.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 21: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_022.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 22: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_023.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 23: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_024.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 24: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_025.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 25: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_026.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 26: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_027.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 27: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_028.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 28: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_029.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 29: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_030.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 30: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_031.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 31: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_032.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 32: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_033.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 33: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_034.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 34: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_035.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 35: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_036.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 36: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_037.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 37: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_038.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 38: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_039.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 39: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_040.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 40: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_041.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 41: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_042.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 42: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_043.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 43: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_044.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 44: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_045.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 45: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_046.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 46: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_047.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 47: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_048.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 48: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_049.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 49: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_050.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 50: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_051.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 51: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_052.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 52: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_053.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 53: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_054.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 54: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_055.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 55: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_056.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 56: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_057.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 57: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_058.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 58: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_059.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 59: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_060.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 60: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_061.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 61: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_062.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 62: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_063.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 63: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_064.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 64: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_065.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 65: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_066.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 66: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_067.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 67: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_068.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 68: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_069.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 69: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_070.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 70: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_071.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 71: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_072.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 72: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_073.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 73: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_074.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 74: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_075.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 75: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_076.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 76: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_077.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 77: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_078.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 78: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_079.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 79: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_080.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 80: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_081.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 81: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_082.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 82: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_083.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 83: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_084.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 84: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_085.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 85: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_086.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 86: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_087.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 87: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_088.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 88: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_089.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 89: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_090.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 90: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_091.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 91: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_092.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 92: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_093.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 93: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_094.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 94: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_095.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 95: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_096.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 96: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_097.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 97: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_098.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 98: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_099.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 99: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /commit_100.csv: -------------------------------------------------------------------------------- 1 | Commit Message 2 | Commit 100: Update related to face recognition module 3 | -------------------------------------------------------------------------------- /windows_setup.txt: -------------------------------------------------------------------------------- 1 | cmake==3.17.2 2 | dlib==19.18.0 3 | opencv-python==4.6.0.66 4 | Pillow==9.2.0 5 | face_recognition==1.3.0 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple Face Recognition Desktop App 2 | 3 | A simple desktop application for face recognition using Python. This app utilizes popular libraries such as `dlib` and `face_recognition` to detect and recognize faces in images. 4 | 5 | ## Technologies 6 | 7 | - **Python**: The programming language used for the application. 8 | - **dlib**: A toolkit for machine learning and computer vision tasks, used for face detection and recognition. 9 | - **OpenCV**: A library for computer vision tasks, utilized here for image processing. 10 | - **Pillow**: A Python Imaging Library (PIL) fork, used for opening, manipulating, and saving image files. 11 | - **face_recognition**: A library built on `dlib` for face recognition. 12 | 13 | ## Setup Requirements 14 | 15 | To set up the project, you need to install the following dependencies: 16 | 17 | - `cmake==3.17.2` 18 | - `dlib==19.18.0` 19 | - `opencv-python==4.6.0.66` 20 | - `Pillow==9.2.0` 21 | - `face_recognition==1.3.0` 22 | 23 | ## Installation 24 | 25 | 1. **Clone the repository**: 26 | 27 | ```bash 28 | git clone https://github.com/.... 29 | cd .... 30 | ``` 31 | 32 | 2. **Set up a virtual environment** (recommended): 33 | 34 | ```bash 35 | python -m venv venv 36 | source venv/bin/activate # On Windows, use `venv\Scripts\activate` 37 | ``` 38 | 39 | 3. **Install dependencies**: 40 | 41 | ```bash 42 | pip install -r requirements.txt 43 | ``` 44 | 45 | Create a `requirements.txt` file with the following content: 46 | 47 | ``` 48 | dlib==19.18.0 49 | opencv-python==4.6.0.66 50 | Pillow==9.2.0 51 | face_recognition==1.3.0 52 | ``` 53 | 54 | Ensure `cmake` is installed on your system. You can download it from [CMake's official website](https://cmake.org/download/). 55 | 56 | 4. **Run the application**: 57 | 58 | ```bash 59 | python main.py 60 | ``` 61 | 62 | ## Usage 63 | 64 | 1. **Load an image**: The app will prompt you to select an image file for processing. 65 | 66 | 2. **Face recognition**: The app will detect and recognize faces in the image and display the results. 67 | 68 | 3. **Save results**: Optionally, save the processed image with recognized faces annotated. 69 | 70 | ## Contributing 71 | 72 | Feel free to fork the repository and submit pull requests for improvements or bug fixes. Please make sure to follow the code style and include tests for new features. 73 | -------------------------------------------------------------------------------- /util.py: -------------------------------------------------------------------------------- 1 | """ 2 | UTILITIES FOR MAIN FACIAL RECOGNITION APPLICATION 3 | """ 4 | 5 | import os 6 | import pickle 7 | 8 | import tkinter as tk 9 | from tkinter import messagebox 10 | import face_recognition 11 | 12 | 13 | # Create a button with specified properties and return it 14 | def get_button(window, text, color, command, fg='white'): 15 | button = tk.Button( 16 | window, 17 | text=text, 18 | activebackground="black", 19 | activeforeground="white", 20 | fg=fg, 21 | bg=color, 22 | command=command, 23 | height=2, 24 | width=20, 25 | font=('Helvetica bold', 20) 26 | ) 27 | return button 28 | 29 | 30 | # Create a label for displaying images and return it 31 | def get_img_label(window): 32 | label = tk.Label(window) 33 | label.grid(row=0, column=0) 34 | return label 35 | 36 | 37 | # Create a text label with specified text and return it 38 | def get_text_label(window, text): 39 | label = tk.Label(window, text=text) 40 | label.config(font=("sans-serif", 21), justify="left") 41 | return label 42 | 43 | 44 | # Create a text entry field and return it 45 | def get_entry_text(window): 46 | inputtxt = tk.Text(window, height=2, width=15, font=("Arial", 32)) 47 | return inputtxt 48 | 49 | 50 | # Display a message box with a title and description 51 | def msg_box(title, description): 52 | messagebox.showinfo(title, description) 53 | 54 | 55 | # Recognize a face from the provided image using the database at db_path 56 | def recognize(img, db_path): 57 | # Extract face embeddings from the given image 58 | embeddings_unknown = face_recognition.face_encodings(img) 59 | 60 | # If no face is found in the image, return 'no_persons_found' 61 | if len(embeddings_unknown) == 0: 62 | return 'no_persons_found' 63 | else: 64 | embeddings_unknown = embeddings_unknown[0] 65 | 66 | # List all files in the database directory 67 | db_dir = sorted(os.listdir(db_path)) 68 | 69 | match = False 70 | j = 0 71 | 72 | # Iterate through the database files to find a match 73 | while not match and j < len(db_dir): 74 | path_ = os.path.join(db_path, db_dir[j]) 75 | 76 | # Load the embeddings from the current database file 77 | file = open(path_, 'rb') 78 | embeddings = pickle.load(file) 79 | 80 | # Compare the current embeddings with the unknown face embeddings 81 | match = face_recognition.compare_faces([embeddings], embeddings_unknown)[0] 82 | j += 1 83 | 84 | # If a match is found, return the username (file name without extension) 85 | if match: 86 | return db_dir[j - 1][:-7] 87 | else: 88 | return 'unknown_person' 89 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Face Recognition Desktop App 3 | 4 | This application provides a simple interface for user login, logout, and registration using face recognition. 5 | It uses libraries like dlib, OpenCV, and face_recognition to detect and recognize faces. 6 | 7 | Dependencies: 8 | - cmake==3.17.2 9 | - dlib==19.18.0 10 | - opencv-python==4.6.0.66 11 | - Pillow==9.2.0 12 | - face_recognition==1.3.0 13 | """ 14 | 15 | import os.path 16 | import datetime 17 | import pickle 18 | 19 | import tkinter as tk 20 | import cv2 21 | from PIL import Image, ImageTk 22 | import face_recognition 23 | 24 | import util 25 | 26 | 27 | # Main Window User Interface setup 28 | class App: 29 | def __init__(self): 30 | self.main_window = tk.Tk() 31 | self.main_window.geometry("1200x520+350+100") 32 | 33 | self.login_button_main_window = util.get_button(self.main_window, 'login', 'blue', self.login) 34 | self.login_button_main_window.place(x=750, y=200) 35 | 36 | self.logout_button_main_window = util.get_button(self.main_window, 'logout', 'red', self.logout) 37 | self.logout_button_main_window.place(x=750, y=300) 38 | 39 | self.register_new_user_button_main_window = util.get_button(self.main_window, 'register new user', 'gray', 40 | self.register_new_user, fg='black') 41 | self.register_new_user_button_main_window.place(x=750, y=400) 42 | 43 | self.webcam_label = util.get_img_label(self.main_window) 44 | self.webcam_label.place(x=10, y=0, width=700, height=500) 45 | 46 | self.add_webcam(self.webcam_label) 47 | 48 | self.db_dir = './db' 49 | if not os.path.exists(self.db_dir): 50 | os.mkdir(self.db_dir) 51 | 52 | self.log_path = './log.txt' 53 | 54 | # Accessing user webcam 55 | def add_webcam(self, label): 56 | for index in range(10): 57 | cap = cv2.VideoCapture(index) 58 | if cap.isOpened(): 59 | self.cap = cap 60 | break 61 | else: 62 | raise Exception("No webcam found.") 63 | 64 | self._label = label 65 | self.process_webcam() 66 | 67 | # Processing webcam image 68 | def process_webcam(self): 69 | ret, frame = self.cap.read() 70 | if not ret: 71 | print("Failed to capture image from webcam.") 72 | self._label.after(20, self.process_webcam) # Retry after 20 ms 73 | return 74 | 75 | self.most_recent_capture_arr = frame 76 | img_ = cv2.cvtColor(self.most_recent_capture_arr, cv2.COLOR_BGR2RGB) 77 | self.most_recent_capture_pil = Image.fromarray(img_) 78 | imgtk = ImageTk.PhotoImage(image=self.most_recent_capture_pil) 79 | self._label.imgtk = imgtk 80 | self._label.configure(image=imgtk) 81 | 82 | self._label.after(20, self.process_webcam) 83 | 84 | # User login functionality 85 | def login(self): 86 | name = util.recognize(self.most_recent_capture_arr, self.db_dir) 87 | if name in ['unknown_person', 'no_persons_found']: 88 | util.msg_box('Ups...', 'Unknown user. Please register new user or try again.') 89 | else: 90 | util.msg_box('Welcome back!', 'Welcome, {}.'.format(name)) 91 | with open(self.log_path, 'a') as f: 92 | f.write('{},{},in\n'.format(name, datetime.datetime.now())) 93 | 94 | # User logout functionality 95 | def logout(self): 96 | name = util.recognize(self.most_recent_capture_arr, self.db_dir) 97 | if name in ['unknown_person', 'no_persons_found']: 98 | util.msg_box('Ups...', 'Unknown user. Please register new user or try again.') 99 | else: 100 | util.msg_box('Hasta la vista!', 'Goodbye, {}.'.format(name)) 101 | with open(self.log_path, 'a') as f: 102 | f.write('{},{},out\n'.format(name, datetime.datetime.now())) 103 | 104 | # Function to register new user 105 | def register_new_user(self): 106 | self.register_new_user_window = tk.Toplevel(self.main_window) 107 | self.register_new_user_window.geometry("1200x520+370+120") 108 | 109 | self.accept_button_register_new_user_window = util.get_button(self.register_new_user_window, 'Accept', 'green', self.accept_register_new_user) 110 | self.accept_button_register_new_user_window.place(x=750, y=300) 111 | 112 | 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) 113 | self.try_again_button_register_new_user_window.place(x=750, y=400) 114 | 115 | self.capture_label = util.get_img_label(self.register_new_user_window) 116 | self.capture_label.place(x=10, y=0, width=700, height=500) 117 | 118 | self.add_img_to_label(self.capture_label) 119 | 120 | self.entry_text_register_new_user = util.get_entry_text(self.register_new_user_window) 121 | self.entry_text_register_new_user.place(x=750, y=150) 122 | 123 | self.text_label_register_new_user = util.get_text_label(self.register_new_user_window, 'Please, \ninput username:') 124 | self.text_label_register_new_user.place(x=750, y=70) 125 | 126 | # Closes window to reregister user if failed. 127 | def try_again_register_new_user(self): 128 | self.register_new_user_window.destroy() 129 | 130 | #Updates the Interface label with most recent capture 131 | def add_img_to_label(self, label): 132 | imgtk = ImageTk.PhotoImage(image=self.most_recent_capture_pil) 133 | label.imgtk = imgtk 134 | label.configure(image=imgtk) 135 | 136 | self.register_new_user_capture = self.most_recent_capture_arr.copy() 137 | 138 | # This begins the main event loop for the application. 139 | def start(self): 140 | self.main_window.mainloop() 141 | 142 | # Registers a new user by saving their face embeddings to a file. 143 | def accept_register_new_user(self): 144 | name = self.entry_text_register_new_user.get(1.0, "end-1c") 145 | 146 | embeddings = face_recognition.face_encodings(self.register_new_user_capture)[0] 147 | 148 | file_path = os.path.join(self.db_dir, '{}.pickle'.format(name)) 149 | with open(file_path, 'wb') as file: 150 | pickle.dump(embeddings, file) 151 | 152 | util.msg_box('Success!', 'User was registered successfully!') 153 | 154 | self.register_new_user_window.destroy() 155 | 156 | 157 | if __name__ == "__main__": 158 | app = App() 159 | app.start() 160 | --------------------------------------------------------------------------------