├── Face_Recognizer ├── Face_Recognizer.png ├── MainUI.png ├── __init__.py ├── backg.jpg ├── build_negative.py ├── build_positive.py ├── cnn_model.py ├── create_test_case.py ├── detect_face.py ├── haarcascade_frontalface_default.xml ├── load_cnn_from_file.py ├── main_ui.py ├── nameslist.txt └── temimg.jpg └── README.md /Face_Recognizer/Face_Recognizer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neeru1207/GUI-Face-recognizer/4c68df7b64ab7931f5921a5834c26c4bfc0b3c5c/Face_Recognizer/Face_Recognizer.png -------------------------------------------------------------------------------- /Face_Recognizer/MainUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neeru1207/GUI-Face-recognizer/4c68df7b64ab7931f5921a5834c26c4bfc0b3c5c/Face_Recognizer/MainUI.png -------------------------------------------------------------------------------- /Face_Recognizer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neeru1207/GUI-Face-recognizer/4c68df7b64ab7931f5921a5834c26c4bfc0b3c5c/Face_Recognizer/__init__.py -------------------------------------------------------------------------------- /Face_Recognizer/backg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neeru1207/GUI-Face-recognizer/4c68df7b64ab7931f5921a5834c26c4bfc0b3c5c/Face_Recognizer/backg.jpg -------------------------------------------------------------------------------- /Face_Recognizer/build_negative.py: -------------------------------------------------------------------------------- 1 | '''Download the faces.tar file from http://www.vision.caltech.edu/Image_Datasets/faces 2 | Extract to a folder named faces and copy the folder into FaceRecognizer directory 3 | This script processes the faces's images to form the negative part of the dataset 4 | ''' 5 | import os 6 | import cv2 7 | import shutil 8 | 9 | class BuildNegativeDataset: 10 | def __init__(self): 11 | self.src_path = "faces" 12 | self.target_path = "dataset/train/No" 13 | self.detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") 14 | self.imgnum = 1 15 | 16 | def create_dataset(self): 17 | try: 18 | os.makedirs(self.target_path) 19 | except: 20 | return 21 | for r, d, f in os.walk(self.src_path): 22 | for file in f: 23 | if '.jpg' in file: 24 | img = cv2.imread(str(self.src_path+"/"+str(file))) 25 | print("Read "+self.src_path+"/"+str(file)) 26 | grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 27 | face = self.detector.detectMultiScale(image=grayimg, scaleFactor=1.1, minNeighbors=5) 28 | for x, y, w, h in face: 29 | new_img = img[y:y+h, x:x+w] 30 | cv2.imwrite(str(self.target_path+"/"+str(self.imgnum)+".jpg"), new_img) 31 | self.imgnum += 1 32 | def reset(self): 33 | self.imgnum = 1 34 | shutil.rmtree(self.target_path) 35 | -------------------------------------------------------------------------------- /Face_Recognizer/build_positive.py: -------------------------------------------------------------------------------- 1 | import time 2 | import cv2 3 | import os 4 | import shutil 5 | '''Opens the webcam, then: 6 | Repeatedly: 7 | Detects a face from the web cam video stream. 8 | Draws a rectangle around the face. 9 | If k is pressed: 10 | Saves the rectangular part as an image. 11 | If q is pressed: 12 | Closes the webcam and terminates. 13 | The saved images form the positive data in the data set for face recognition. 14 | ''' 15 | class BuildPositiveFaceDataset: 16 | def __init__(self): 17 | self.num_of_images = 0 18 | self.detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") 19 | self.name = None 20 | self.path = None 21 | 22 | def set_name(self, name): 23 | self.name = name 24 | self.path = "dataset/train/" + self.name 25 | 26 | def start_capture(self): 27 | try: 28 | os.makedirs(self.path) 29 | except: 30 | return 31 | vid = cv2.VideoCapture(0) 32 | while True: 33 | ret, img = vid.read() 34 | new_img = None 35 | grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 36 | face = self.detector.detectMultiScale(image=grayimg, scaleFactor=1.1, minNeighbors=5) 37 | for x, y, w, h in face: 38 | cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2) 39 | cv2.putText(img, "Face Detected", (x, y-5), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0)) 40 | cv2.putText(img, str(str(self.num_of_images)+" images captured"), (x, y+h+20), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0)) 41 | new_img = img[y:y+h, x:x+w] 42 | cv2.imshow("FaceDetection", img) 43 | key = cv2.waitKey(1) & 0xFF 44 | if key == ord("k"): 45 | self.num_of_images += 1 46 | cv2.imwrite(str(self.path+"/"+str(self.num_of_images)+".jpg"), new_img) 47 | elif key == ord("q") or key == 27: 48 | break 49 | cv2.destroyAllWindows() 50 | 51 | def reset(self): 52 | self.num_of_images = 0 53 | try: 54 | shutil.rmtree(self.path) 55 | except: 56 | pass -------------------------------------------------------------------------------- /Face_Recognizer/cnn_model.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import cv2 3 | import numpy as np 4 | 5 | class CNN: 6 | def __init__(self): 7 | self.classifier = tf.keras.models.Sequential() 8 | self.classifier.add(tf.keras.layers.Conv2D(32, (3, 3), input_shape=(64, 64, 3), activation='relu')) 9 | self.classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2))) 10 | self.classifier.add(tf.keras.layers.Conv2D(32, (3, 3), activation='relu')) 11 | self.classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2))) 12 | self.classifier.add(tf.keras.layers.Flatten()) 13 | self.classifier.add(tf.keras.layers.Dense(units=128, activation='relu')) 14 | self.classifier.add(tf.keras.layers.Dense(units=1, activation='sigmoid')) 15 | self.train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255, 16 | shear_range=0.2, 17 | zoom_range=0.2, 18 | horizontal_flip=True) 19 | self.test_datagen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255) 20 | self.training_set = None 21 | self.test_set = None 22 | self.predict_datagen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1. / 255) 23 | self.pers_name = None 24 | 25 | def create_train_test(self): 26 | self.training_set = self.train_datagen.flow_from_directory('dataset/train/', 27 | classes=["No", self.pers_name], 28 | target_size=(64, 64), 29 | batch_size=32, 30 | class_mode='binary') 31 | self.label_map = (self.training_set.class_indices) 32 | self.pos_class_label = self.label_map[self.pers_name] 33 | self.test_set = self.test_datagen.flow_from_directory('dataset/test/',classes=["No", self.pers_name], 34 | target_size=(64, 64), 35 | batch_size=32, 36 | class_mode='binary') 37 | with open(str(self.pers_name+"poslabel.txt"), "w") as x: 38 | x.write(str(self.pos_class_label)) 39 | 40 | def compile(self): 41 | self.classifier.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) 42 | 43 | def set_name(self, name): 44 | self.pers_name = name 45 | 46 | def fit_generate(self): 47 | self.classifier.fit_generator(self.training_set, 48 | samples_per_epoch=400, 49 | nb_epoch=25, 50 | validation_data=self.test_set, 51 | nb_val_samples=100) 52 | 53 | def make_prediction(self): 54 | img1 = tf.keras.preprocessing.image.load_img('temimg.jpg', target_size=(64, 64)) 55 | img1 = tf.keras.preprocessing.image.img_to_array(img1) 56 | img1 = cv2.resize(img1, (64, 64)) 57 | img1 = np.expand_dims(img1, axis=0) 58 | result = self.classifier.predict(img1) 59 | if result[0][0] == self.pos_class_label: 60 | return True 61 | else: 62 | return False 63 | 64 | -------------------------------------------------------------------------------- /Face_Recognizer/create_test_case.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | 3 | class CreateTestSet: 4 | def __init__(self): 5 | self.src_path = "dataset/train" 6 | self.dest_path = "dataset/test" 7 | 8 | def run(self): 9 | shutil.copytree(self.src_path, self.dest_path) 10 | 11 | def reset(self): 12 | try: 13 | shutil.rmtree(self.dest_path) 14 | except: 15 | pass -------------------------------------------------------------------------------- /Face_Recognizer/detect_face.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import time 3 | 4 | 5 | class DetectFace: 6 | def __init__(self, name, CNNinst): 7 | self.detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") 8 | self.name = name 9 | vid = cv2.VideoCapture(0) 10 | time.sleep(2) 11 | while True: 12 | ret, img = vid.read() 13 | new_img = None 14 | grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 15 | face = self.detector.detectMultiScale(image=grayimg, scaleFactor=1.1, minNeighbors=5) 16 | for x, y, w, h in face: 17 | new_img = img[y:y + h, x:x + w] 18 | cv2.imwrite("temimg.jpg", new_img) 19 | if CNNinst.make_prediction(): 20 | cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) 21 | cv2.putText(img, self.name, (x+w, y+h), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), thickness = 2) 22 | else: 23 | cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2) 24 | cv2.putText(img, str("Not "+self.name), (x + w, y + h), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), thickness=2) 25 | cv2.imshow("FaceRecognition", img) 26 | key = cv2.waitKey(30) & 0xFF 27 | if key == ord("q"): 28 | break 29 | cv2.destroyAllWindows() 30 | -------------------------------------------------------------------------------- /Face_Recognizer/load_cnn_from_file.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | 4 | 5 | class LoadCnn: 6 | def __init__(self, name): 7 | self.pers_name = name 8 | filname = (str(name)+".h5") 9 | self.classifier = tf.keras.models.load_model(filname) 10 | self.pos_label = None 11 | 12 | def make_prediction(self): 13 | img1 = tf.keras.preprocessing.image.load_img('temimg.jpg', target_size=(64, 64)) 14 | img1 = tf.keras.preprocessing.image.img_to_array(img1) 15 | img1 = np.expand_dims(img1, axis=0) 16 | result = self.classifier.predict(img1) 17 | self.pos_label = None 18 | with open(str(self.pers_name+"poslabel.txt"), "r") as x: 19 | self.pos_label = int(x.read()) 20 | if result[0][0] == self.pos_label: 21 | return True 22 | else: 23 | return False 24 | -------------------------------------------------------------------------------- /Face_Recognizer/main_ui.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import font as tkfont 3 | from tkinter import filedialog, messagebox 4 | from Face_Recognizer.cnn_model import CNN 5 | from Face_Recognizer.build_positive import BuildPositiveFaceDataset 6 | from Face_Recognizer.detect_face import DetectFace 7 | from Face_Recognizer.create_test_case import CreateTestSet 8 | from Face_Recognizer.build_negative import BuildNegativeDataset 9 | from Face_Recognizer.load_cnn_from_file import LoadCnn 10 | from PIL import ImageTk, Image 11 | import shutil 12 | names = set() 13 | 14 | class MainUI(tk.Tk): 15 | 16 | def __init__(self, *args, **kwargs): 17 | tk.Tk.__init__(self, *args, **kwargs) 18 | global names 19 | with open("nameslist.txt", "r") as f: 20 | x = f.read() 21 | z = x.rstrip().split(" ") 22 | for i in z: 23 | names.add(i) 24 | self.title_font = tkfont.Font(family='Helvetica', size=16, weight="bold") 25 | self.title("Face Recognizer") 26 | self.resizable(False, False) 27 | self.geometry("300x150") 28 | self.CNNobj = None 29 | self.Buildposobj = BuildPositiveFaceDataset() 30 | self.BuildNegobj = BuildNegativeDataset() 31 | self.BuildNegobj.create_dataset() 32 | self.createtest = CreateTestSet() 33 | self.active_name = None 34 | self.protocol("WM_DELETE_WINDOW", self.on_closing) 35 | container = tk.Frame(self) 36 | container.grid(sticky="nsew") 37 | container.grid_rowconfigure(0, weight=1) 38 | container.grid_columnconfigure(0, weight=1) 39 | self.frames = {} 40 | for F in (StartPage, PageOne, PageTwo, PageThree, PageFour): 41 | page_name = F.__name__ 42 | frame = F(parent=container, controller=self) 43 | self.frames[page_name] = frame 44 | frame.grid(row=0, column=0, sticky="nsew") 45 | self.show_frame("StartPage") 46 | 47 | def show_frame(self, page_name): 48 | frame = self.frames[page_name] 49 | frame.tkraise() 50 | 51 | def on_closing(self): 52 | if messagebox.askokcancel("Quit", "Are you sure?"): 53 | global names 54 | with open("nameslist.txt", "w") as f: 55 | for i in names: 56 | f.write(i+" ") 57 | try: 58 | shutil.rmtree("dataset/test") 59 | except: 60 | pass 61 | self.destroy() 62 | 63 | 64 | class StartPage(tk.Frame): 65 | 66 | def __init__(self, parent, controller): 67 | tk.Frame.__init__(self, parent) 68 | self.controller = controller 69 | load = Image.open("backg.jpg") 70 | load = load.resize((150, 150), Image.ANTIALIAS) 71 | render = ImageTk.PhotoImage(load) 72 | img = tk.Label(self, image=render) 73 | img.image = render 74 | img.grid(row=0, column=1, rowspan=4, sticky="nsew") 75 | label = tk.Label(self, text="Face Recognizer", font=controller.title_font, fg="darkblue") 76 | label.grid(row=0, sticky="ew") 77 | button1 = tk.Button(self, text="Add a new user", fg="darkblue", bg="lightblue", 78 | command=lambda: controller.show_frame("PageOne")) 79 | button2 = tk.Button(self, text="Select existing user", fg="darkblue", bg="lightblue", 80 | command=lambda: controller.show_frame("PageTwo")) 81 | button3 = tk.Button(self, text="Quit", fg="darkblue", bg="lightblue", command=self.on_closing) 82 | button1.grid(row=2, column=0, ipady=3, ipadx=7) 83 | button2.grid(row=1, column=0, ipady=3, ipadx=0) 84 | button3.grid(row=3, column=0, ipady=2, ipadx=34) 85 | 86 | def on_closing(self): 87 | if messagebox.askokcancel("Quit", "Are you sure?"): 88 | global names 89 | with open("nameslist.txt", "w") as f: 90 | for i in names: 91 | f.write(i+" ") 92 | try: 93 | shutil.rmtree("dataset/test") 94 | except: 95 | pass 96 | self.controller.destroy() 97 | 98 | 99 | class PageOne(tk.Frame): 100 | 101 | def __init__(self, parent, controller): 102 | tk.Frame.__init__(self, parent) 103 | self.controller = controller 104 | tk.Label(self, text="Enter the name", fg="blue", font='Helvetica 12 bold').grid(row=0, column=0, pady=10, padx=5) 105 | self.user_name = tk.Entry(self, borderwidth=3, bg="lightgrey", font='Helvetica 11') 106 | self.user_name.grid(row=0, column=1, pady=10, padx=10) 107 | self.controller.CNNobj = CNN() 108 | self.buttoncanc = tk.Button(self, text="Cancel", fg="red", bg="lightblue", command=lambda: controller.show_frame("StartPage")) 109 | self.buttonext = tk.Button(self, text="Next", fg="green", bg="lightblue", command=self.start_training) 110 | self.buttoncanc.grid(row=1, column=0, pady=10, ipadx=5, ipady=4) 111 | self.buttonext.grid(row=1, column=1, pady=10, ipadx=5, ipady=4) 112 | 113 | def start_training(self): 114 | global names 115 | if self.user_name.get() == "None": 116 | messagebox.showerror("Error", "Name cannot be 'None'") 117 | return 118 | if self.user_name.get() in names: 119 | messagebox.showerror("Error", "User already exists!") 120 | return 121 | if len(self.user_name.get()) == 0: 122 | messagebox.showerror("Error", "Name cannot be empty!") 123 | return 124 | name = self.user_name.get() 125 | names.add(name) 126 | self.controller.active_name = name 127 | self.controller.Buildposobj.set_name(name) 128 | self.controller.CNNobj.set_name(name) 129 | self.controller.frames["PageTwo"].refresh_names() 130 | self.controller.show_frame("PageThree") 131 | 132 | 133 | class PageTwo(tk.Frame): 134 | 135 | def __init__(self, parent, controller): 136 | tk.Frame.__init__(self, parent) 137 | global names 138 | self.controller = controller 139 | tk.Label(self, text="Select user", fg="blue", font='Helvetica 12 bold').grid(row=0, column=0, padx=10, pady=10) 140 | self.buttoncanc = tk.Button(self, text="Cancel", command=lambda: controller.show_frame("StartPage"), fg="red", bg="lightblue") 141 | self.menuvar = tk.StringVar(self) 142 | self.dropdown = tk.OptionMenu(self, self.menuvar, *names) 143 | self.dropdown.config(bg="lightgrey") 144 | self.dropdown["menu"].config(bg="lightgrey") 145 | self.buttonext = tk.Button(self, text="Next", command=self.nextfoo, fg="green", bg="lightblue") 146 | self.dropdown.grid(row=0, column=1, ipadx=8, padx=10, pady=10) 147 | self.buttoncanc.grid(row=1, ipadx=5, ipady=4, column=0, pady=10) 148 | self.buttonext.grid(row=1, ipadx=5, ipady=4, column=1, pady=10) 149 | 150 | def nextfoo(self): 151 | if self.menuvar.get() == "None": 152 | messagebox.showerror("ERROR", "Name cannot be 'None'") 153 | return 154 | self.controller.active_name = self.menuvar.get() 155 | self.controller.CNNobj = LoadCnn(self.controller.active_name) 156 | self.controller.show_frame("PageFour") 157 | 158 | def refresh_names(self): 159 | global names 160 | self.menuvar.set('') 161 | self.dropdown['menu'].delete(0, 'end') 162 | for name in names: 163 | self.dropdown['menu'].add_command(label=name, command=tk._setit(self.menuvar, name)) 164 | 165 | class PageThree(tk.Frame): 166 | 167 | def __init__(self, parent, controller): 168 | tk.Frame.__init__(self, parent) 169 | self.controller = controller 170 | self.numimglabel = tk.Label(self, text="Number of images captured = 0", font='Helvetica 12 bold', fg="blue") 171 | self.numimglabel.grid(row=0, column=0, columnspan=2, sticky="ew", pady=10) 172 | self.capturebutton = tk.Button(self, text="Capture images", fg="darkblue", bg="lightblue", command=self.capimg) 173 | self.trainbutton = tk.Button(self, text="Start training the model", fg="darkblue", bg="lightblue", 174 | command=self.trainmodel) 175 | self.capturebutton.grid(row=1, column=0, ipadx=5, ipady=4, padx=10, pady=20) 176 | self.trainbutton.grid(row=1, column=1, ipadx=5, ipady=4, padx=10, pady=20) 177 | 178 | def capimg(self): 179 | messagebox.showinfo("INSTRUCTIONS", "Now your web cam will be opened. Capture at least 200 images with varied facial expressions. Press k to capture an image. Press q or ESC to exit.") 180 | self.controller.Buildposobj.start_capture() 181 | x = self.controller.Buildposobj.num_of_images 182 | self.numimglabel.config(text=str("Number of images captured = "+str(x))) 183 | 184 | def trainmodel(self): 185 | if self.controller.Buildposobj.num_of_images < 300: 186 | messagebox.showerror("ERROR", "Capture at least 300 images!") 187 | return 188 | self.controller.createtest.run() 189 | self.controller.CNNobj.compile() 190 | self.controller.CNNobj.create_train_test() 191 | self.controller.CNNobj.fit_generate() 192 | self.controller.CNNobj.classifier.save(str(self.controller.CNNobj.pers_name+".h5")) 193 | messagebox.showinfo("SUCCESS", "The CNN has been successfully trained!") 194 | self.controller.show_frame("PageFour") 195 | 196 | class PageFour(tk.Frame): 197 | 198 | def __init__(self, parent, controller): 199 | tk.Frame.__init__(self, parent) 200 | self.controller = controller 201 | label = tk.Label(self, text="Face Recognition", font='Helvetica 16 bold') 202 | label.grid(row=0, sticky="ew") 203 | button1 = tk.Button(self, text="Open web cam for Face Recognition", 204 | command=self.openwebcam, fg="darkblue", bg="lightblue") 205 | button2 = tk.Button(self, text="Go to Home", command=lambda:self.controller.show_frame("StartPage"), fg="red", bg="lightblue") 206 | button1.grid(row=1, sticky="ew", ipadx=5, ipady=4, padx=10, pady=10) 207 | button2.grid(row=2, sticky="ew", ipadx=5, ipady=4, padx=10, pady=10) 208 | def openwebcam(self): 209 | DetectFace(self.controller.active_name, self.controller.CNNobj) 210 | 211 | 212 | app = MainUI() 213 | app.mainloop() -------------------------------------------------------------------------------- /Face_Recognizer/nameslist.txt: -------------------------------------------------------------------------------- 1 | None Neeru -------------------------------------------------------------------------------- /Face_Recognizer/temimg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neeru1207/GUI-Face-recognizer/4c68df7b64ab7931f5921a5834c26c4bfc0b3c5c/Face_Recognizer/temimg.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GUI Face recognizer 2 | A GUI based webcam realtime video Face Recognizer coded in Python3 for Windows. 3 | # Screenshots 4 | !["Main UI"](https://github.com/neeru1207/GUI-Face-recognizer/blob/master/Face_Recognizer/MainUI.png) 5 | !["Face Recognition"](https://github.com/neeru1207/GUI-Face-recognizer/blob/master/Face_Recognizer/Face_Recognizer.png) 6 | ## Usage: 7 | ### Required download: 8 | * Download the faces.tar file from [here](http://www.vision.caltech.edu/Image_Datasets/faces). 9 | * Extract to a folder named faces and move the folder into the Face Recognizer folder. 10 | ### Required Packages: 11 | Install [Python3](https://www.python.org/downloads/) and [Anaconda](https://www.anaconda.com/distribution/) if you haven't. 12 | * Create a new conda environment 13 | ````shell 14 | conda create --name envname 15 | ```` 16 | * Activate the environment 17 | ````shell 18 | conda activate envname 19 | ```` 20 | * Install Keras, OpenCV, Numpy, h5py and PIL: 21 | ````shell 22 | conda install keras 23 | conda install opencv 24 | conda install numpy 25 | conda install h5py 26 | conda install pillow 27 | ```` 28 | ### Running the application 29 | ````shell 30 | cd Face Recognizer 31 | python main_ui.py 32 | ```` 33 | ## Implementation: 34 | ### Dataset 35 | #### "NO" class: 36 | * The [faces](http://www.vision.caltech.edu/Image_Datasets/faces) dataset forms the __NO__ class of the dataset. 37 | #### "YES" class: 38 | * [Frontal face Haar cascade](https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_default.xml) is used for webcam based face detection in OpenCV. 39 | * The detected face in every frame of the video stream is cropped and saved as an image. 40 | * This forms the "YES" class of the dataset 41 | #### Augmentation: 42 | * Since the dataset is rather small, __Keras Image data generator__ is used for Image augmentation. 43 | ### Model: 44 | * A __Convolutional Neural Network__ is built using Keras. This model is trained on the constructed dataset over __25 epochs__ with __400__ samples per epoch. 45 | * The loss function used is __Binary crossentropy__ and the optimizer used is __adam__. 46 | * The model is saved after training into a __.h5__ file for later use. 47 | * The class indices are also saved into a __poslabel.txt__ file. 48 | ### Recognition: 49 | * For every frame in the video stream, face is detected using [frontal_face_haar_cascade](https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_default.xml) in Opencv. 50 | * The detected face is saved to a __tmpimg.jpg__ file. 51 | * Th trained CNN model is used to recognize the face. 52 | * The result is shown using __cv.rectangle__ around the face and text. 53 | * Green colored rectangle and Name text if __YES__ else Red colored rectangle and Not Name text. 54 | 55 | --------------------------------------------------------------------------------