-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTraining.py
More file actions
29 lines (22 loc) 路 857 Bytes
/
Copy pathTraining.py
File metadata and controls
29 lines (22 loc) 路 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import cv2
import numpy as np
from os import listdir
from os.path import isfile, join
data_path = 'C:/Users/paula/OneDrive/Desktop/RATNA/dataset'
onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path, f))]
Training_Data, Labels = [], []
for i, file in enumerate(onlyfiles):
image_path = join(data_path, file)
images = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
if images is None:
print(f"Warning: Unable to read {image_path}, skipping.")
continue
Training_Data.append(np.asarray(images, dtype=np.uint8))
Labels.append(i)
if len(Training_Data) == 0:
print("No valid images found for training.")
exit()
Labels = np.asarray(Labels, dtype=np.int32)
model = cv2.face.LBPHFaceRecognizer_create()
model.train(np.asarray(Training_Data), np.asarray(Labels))
print("Dataset Model Training Completed")