Last active
June 23, 2021 05:04
-
-
Save Rishbah-76/8f7b559aa18f019dd5d30ce40ce9bb21 to your computer and use it in GitHub Desktop.
Creating a Face Recognization model using LBPH Algo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Training the Model | |
cap.release() | |
import cv2 | |
import numpy as np | |
from os import listdir | |
from os.path import isfile, join | |
# Get the training data we previously made | |
data_path = './faces/user/' | |
onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path, f))] | |
# Create arrays for training data and labels | |
Training_Data, Labels = [], [] | |
# Open training images in our datapath | |
# Create a numpy array for training data | |
for i, files in enumerate(onlyfiles): | |
image_path = data_path + onlyfiles[i] | |
images = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) | |
Training_Data.append(np.asarray(images, dtype=np.uint8)) | |
Labels.append(i) | |
# Create a numpy array for both training data and labels | |
Labels = np.asarray(Labels, dtype=np.int32) | |
# Initialize facial recognizer | |
# model = cv2.face.createLBPHFaceRecognizer() | |
# NOTE: For OpenCV 3.0 use cv2.face.createLBPHFaceRecognizer() | |
# pip install opencv-contrib-python | |
# model = cv2.createLBPHFaceRecognizer() | |
vimal_model = cv2.face_LBPHFaceRecognizer.create() | |
# Let's train our model | |
vimal_model.train(np.asarray(Training_Data), np.asarray(Labels)) | |
print("Model trained sucessefully") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment