def upload(): target = os.path.join(APP_ROOT, "images/") print(target) if not os.path.isdir(target): os.mkdir(target) i = 0 for file in request.files.getlist("file"): print(file) filename = file.filename destination = "/".join([target, "a" + str(i) + ".png"]) i += 1 print(destination) file.save(destination) save_face1("D:\T\SpitHackathon\src\images/a0.png") img_1 = readImage("D:\T\SpitHackathon\src\images/a.jpeg") save_face2("D:\T\SpitHackathon\src\data/frame0.jpg") img_2 = readImage("D:\T\SpitHackathon\src\images/b.jpeg") output = verify_images(img_1, img_2) if (output): return render_template("complete.html") else: return render_template("notComplete.html")
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))
def generate_np_matrix(source=None): print('Creating Numpy Matrix...') if (source == None): source = os.path.join(os.getcwd(), 'lfw') img_arr = [] for folder in os.listdir(source): folder_path = os.path.join(source, folder) for img in os.listdir(folder_path): img_path = os.path.join(folder_path, img) image = readImage(img_path) ima = np.array(image) img_arr.append(ima) np_arr = np.array(img_arr) print('Numpy Matrix Created.') return np_arr
from model_images import getFaces, readImage 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):
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
arr = np.empty((0,2622), float) def generate_dataframe(data): df = pd.DataFrame(data, columns = feature_col_idx) return df def appendImgToNPA(image, arr, name): print('Processing image ', name) vec = getFeatureVector(image) arr = np.append(arr, [vec], axis = 0) return arr ''' for filename in os.listdir(path): img_path = os.path.join(path, filename) image = readImage(img_path) img = np.asarray(image) image_np = np.empty(img.shape, float) image_np = np.append(image_np, img, axis = 0) image_np = np.append(image_np, img, axis = 0) image = Image.fromarray(image_np) arr = appendImgToNPA(image, arr, filename) ''' for filename in img_list: path = os.path.join(os.getcwd(), 'Yale', filename) img_path = os.path.join(path) image = readImage(img_path) arr = appendImgToNPA(image, arr, path) df = generate_dataframe(arr) df.to_csv(r'Yale_DataFrame.csv', index = False)