-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageTrainer.py
32 lines (26 loc) · 939 Bytes
/
ImageTrainer.py
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
30
31
32
import face_recognition
import os
import cv2
from numpy import save
def findEncoding(img):
image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
faces = face_recognition.face_locations(image)
encode = face_recognition.face_encodings(image, faces)[0]
return encode
def train_image():
path = "StudentDetails/StudentPictures"
encodeList = []
known_face_names = []
known_face_ids = []
for imagefilename in os.listdir(path):
curImg = cv2.imread(path+'/'+imagefilename)
known_face_names.append(imagefilename.split('.')[0])
known_face_ids.append(imagefilename.split('.')[1])
encoding = findEncoding(curImg)
encodeList.append(encoding)
known_faces_data = list(zip(known_face_names, known_face_ids))
save('encode-data.npy', encodeList)
save('known-faces-data.npy', known_faces_data)
print(encodeList)
print(known_faces_data)
print("encoding Complete")