if os.path.exists(imgpaths[0]) and os.path.exists(imgpaths[1]): fm.morpher(imgpaths, alpha=False, width=w, height=h, num_frames=nframes, fps=10, out_frames=outfr, out_video=outvid) else: print('missing %s/%s' % (imgpaths[0], imgpaths[1])) # Creating an average face for em in emotions: imgpaths = glob(os.path.join(imdir, 'stim', '*f_' + em + '_c.png')) fm.averager(imgpaths, alpha=True, blur_edges=True, out_filename='female_' + em + '_c.png') import numpy as np from matplotlib import pyplot as plt from PIL import Image import scipy impath = imgpaths[0] img = scipy.ndimage.imread(impath)[..., :3] points = fm.locator.face_points(impath) plt.imshow(img) plt.plot(points[:, 0], points[:, 1], '.')
import facemorpher import os # Get a list of image paths in a folder photo_path = os.environ['HACKERBRASILEIRO_PHOTO_PATH'] imgpaths = facemorpher.list_imgpaths(photo_path) # To average, supply an array of face images: result_path = os.environ['HACKERBRASILEIRO_FACEMORPHER_PATH'] + '/result.png' facemorpher.averager(imgpaths, out_filename=result_path)
def average(pictures): facemorpher.averager(pictures, plot=True)
# grouped_images[idx].append(img) # #print(f"added to age group{idx}") number_of_people = [1, 2, 3, 5, 7, 10] age_average = np.zeros((len(number_of_people), len(age_groups))) for idx, age_group in zip(range(0, len(age_groups)), age_groups): print(f"Starting age group {idx}") result = [] for a in range(age_group[0], age_group[1]): result.extend(functions.find2(f'{a}*.jpg', '../CACD2000')) print(f"Added age {a}") for n in number_of_people: for i in range(0, 3): out_filename = f"../averages/average{age_group[0]}_{age_group[1]}_N{n}({i}).png" if not os.path.exists(out_filename): facemorpher.averager(random.sample(result, n), plot=True, out_filename=out_filename) age_average[n - 1, idx] = age_average[n - 1, idx] + int( estimate_age.estimate_age(out_filename)) print(f"Estimated age for average face with {n} images.") #print("Age: ", age_average) age_average = age_average / 3 # Get mean age plt.plot([10 * x + 5 for x in range(1, len(age_groups) + 1)], age_average.T) plt.legend(number_of_people) plt.xlabel('Actual age') plt.ylabel('Detected age') plt.show()
#pictures = "" pictures = [] for i in onder_70: print(i) path = find(i,x) print(path) if str(path) != "None": z = find2('*.jpg', path) #pictures = pictures + " " + '"' + str(z[0]) + '"' #print(z) pictures.append(str(z[0])) print(pictures) #facemorpher.morpher(pictures, plot=True) facemorpher.averager(pictures, plot=True) agender = PyAgender() # see available options in __init__() src faces = agender.detect_genders_ages(cv2.imread("/Users/ellen/Documents/Twente/Q2/Introduction to biometrics/Final/result.png")) print(faces) # In[3]: # Vergelijk de gemiddelde leeftijd met de detected leeftijd van de morph van deze leeftijd groep from pyagender import PyAgender import cv2 import matplotlib.pyplot as plt
def upload_file(): # get mom_file and dad_file out of request.files # create a new project in the database # when saving the mom and dad files to server (somewhere in static folder), # add the project id to the end of each file name. # update the new project's database record to fill in the mom_url and dad_url attributes. user = User.query.get(session['user_id']) new_project = Project(user=user) db.session.add(new_project) db.session.commit() project_id = str(new_project.project_id) project_base_dir = os.path.join(app.config['UPLOAD_FOLDER'], 'project_' + project_id) os.mkdir(project_base_dir) mom_file = request.files['mom_file'] if mom_file.filename == '': flash('No selected file') return redirect('/new_project') if mom_file and allowed_file(mom_file.filename): filename = secure_filename( mom_file.filename) #make sure file is secure mom_file.save(os.path.join(project_base_dir, filename)) #/uploads/name.jpeg dad_file = request.files['dad_file'] if dad_file.filename == '': flash('No selected file') return redirect('/new_project') if dad_file and allowed_file(dad_file.filename): filename = secure_filename( dad_file.filename) #make sure file is secure dad_file.save(os.path.join(project_base_dir, filename)) #/uploads/name.jpeg new_project.mom_url = 'project_' + project_id + '/' + mom_file.filename new_project.dad_url = 'project_' + project_id + '/' + dad_file.filename mom = os.path.join(project_base_dir, mom_file.filename) dad = os.path.join(project_base_dir, dad_file.filename) facemorpher.averager(imgpaths=[mom, dad], out_filename=os.path.join(project_base_dir, 'result.png'), blur_edges=True, alpha=True) new_project.baby_url = os.path.join('project_' + project_id + '/', 'result.png') db.session.commit() avi_filename = os.path.join(project_base_dir, 'result.avi') facemorpher.morpher([mom, dad], out_video=avi_filename) #converts avi to mp4 ff = FFmpeg(inputs={avi_filename: None}, outputs={ os.path.join(project_base_dir, 'result.mp4'): '-filter:v "setpts=3.0*PTS"' }) ff.run() new_project.baby_avi = avi_filename new_project.baby_mp4 = os.path.join('project_' + project_id + '/', 'result.mp4') db.session.commit() return redirect("/results/" + project_id)
[ '../CACD2000/32_Oliver_Hudson_0003.jpg', '../CACD2000/38_Mireille_Enos_0005.jpg', '../CACD2000/36_Freddie_Prinze_Jr._0013.jpg' ], [ '../CACD2000/42_Nikolaj_Coster-Waldau_0010.jpg', '../CACD2000/47_Mare_Winningham_0015.jpg', '../CACD2000/42_Paul_Rudd_0002.jpg' ], [ '../CACD2000/53_Dylan_Baker_0001.jpg', '../CACD2000/53_Fran_Drescher_0005.jpg', '../CACD2000/57_David_Hasselhoff_0005.jpg' ], [ '../CACD2000/61_Mark_Hamill_0001.jpg', '../CACD2000/61_Mary_McDonnell_0007.jpg', '../CACD2000/62_David_Patrick_Kelly_0001.jpg' ]] age_average = np.zeros(len(age_groups)) for idx, age_group in zip(range(0, len(age_groups)), age_groups): out_filename = f"../averages/average{age_group[0]}_{age_group[1]}_handpickedN2.png" if not os.path.exists(out_filename): facemorpher.averager(people[idx][0:3], plot=True, out_filename=out_filename) age_average[idx] = age_average[idx] + int( functions.age_estimation(out_filename))
import facemorpher # Get a list of image paths in a folder imgpaths = facemorpher.list_imgpaths('imagefolder') # To morph, supply an array of face images: facemorpher.morpher(imgpaths, plot=True) # To average, supply an array of face images: facemorpher.averager(['image1.png', 'image2.png'], plot=True)