-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddImages.py
34 lines (27 loc) · 908 Bytes
/
addImages.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
33
# coding: utf-8
# In[5]:
import face_recognition as fr
import cv2
import os
import numpy as np
def add_images(workdir):
names = np.load('names.npy')
encodings = np.load('encodings.npy')
folder = os.chdir(workdir+'/images')
for filename in os.listdir(folder):
if not filename in names:
print(filename)
try:
img = fr.load_image_file(filename,mode='RGB')
if img is not None:
encode = fr.face_encodings(img,None,2)[0]
names.append(filename)
encodings.append(encode)
os.chdir('../')
np.save('encodings.npy',encodings)
np.save('names.npy',names)
except Exception:
print("No face found, check the image passed")
os.chdir('../')
workingdir = os.getcwd()
add_images(workingdir)