def getConvImage(name, layer=2, index=0):
    image = model_images.readImage(name, cv_2=True)
    image = model_images.getFaces(image)[0]
    images = getConvList(image, layer=8)
    img = images[index]
    img = Image.fromarray(img)
    return img
def extract_faces(source=None, destination=None):

    if (source == None): source = os.path.join(os.getcwd(), 'lfw_data')
    if (destination == None):
        destination = os.path.join(os.getcwd(), 'lfw_data_faces')

    for folder in os.listdir(source):
        folder_path = os.path.join(source, folder)
        os.mkdir(os.path.join(destination, folder))
        for img in os.listdir(folder_path):
            img_path = os.path.join(folder_path, img)
            print(img_path)
            faces = getFaces(readImage(img_path, cv_2=True))
            if len(faces) > 0:
                face = faces[0]
                face.save(os.path.join(destination, folder, img))
import numpy as np
import cv2
from PIL import Image
import time
import pickle
import os
import pandas as pd

loaded_model = pickle.load(open('model.sav', 'rb'))

while True:

    tic = time.time()

    IMG = readImage('download.jpg', cv_2=True)
    faces = getFaces(IMG)

    if len(faces) != 0:

        face = faces[0]
        vec = getFeatureVector(face)
        cluster = loaded_model.predict([vec])

        path = os.path.join(os.getcwd(), 'Clusters')
        cl_path = os.path.join(path, 'Cluster_' + str(cluster[0]),
                               'cluster_' + str(cluster[0]) + '_data.csv')
        df = pd.read_csv(cl_path)
        vectors = df.to_numpy()

        for r_idx, og_vec in enumerate(vectors):
            if verifyFaceVector(og_vec, vec, print_score=True):
import os
import numpy as np
from PIL import Image
from model_images import getFaces, highlightFaces, readImage, cv2_to_pil

path = os.path.join(os.getcwd(), 'IMDB_Data')
new_path = os.path.join(os.getcwd(), 'Data')

file_no = 0

for file in os.listdir(path):

    print('Processing file: ', file_no, '\n')
    img_dir = os.path.join(path, file)
    list_images = os.listdir(img_dir)
    new_file = os.path.join(new_path, 'file_' + str(file_no))
    os.mkdir(new_file)

    img_no = 0

    for image in list_images:
        img = readImage(os.path.join(img_dir, image), cv_2=True)
        images = getFaces(img)
        if len(images) != 0:
            img = images[0]
            name = str(img_no) + '.jpg'
            save_path = os.path.join(new_file, name)
            img.save(save_path)
            img_no += 1

    file_no += 1
        cl_np = np.asarray(df.drop(columns = 'Unnamed: 0'))
        match_idx = verifyVecMat(np.asarray(vec_matrix[idx]), cl_np)
        if match_idx != None: match_index.append(idx_col[match_idx])
        else:  match_index.append(None)
        time_2 = time.time()
        print('Task: Query Dataframe        Time Required: ', time_2-time_1)
    return match_index

preload_dataframe()

while True:

    scr_pil = np.array(ImageGrab.grab(bbox = (0, 100, 400, 300)))
    scr_cv = cv2.cvtColor(scr_pil, cv2.COLOR_BGR2RGB)
    time0 = time.time()
    faces = getFaces(scr_cv)
    time1 = time.time()
    print('Task: Extract Faces          Time Required: ', time1-time0)

    faces = np.asarray([np.asarray(face) for face in faces])
    time2 = time.time()
    print('Task: Faces as Numpy         Time Required: ', time2-time1)

    print(len(faces), ' faces detected.')

    text = []

    if len(faces) > 0:
        time3 = time.time()
        vec_matrix = getFeatureVector(faces, matrix = True)
        time4 = time.time()