示例#1
0
def morphing(orginele_foto, morph_foto):
    faces = agender.detect_genders_ages(cv2.imread(orginele_foto))
    original_age = faces[0]['age']
    pictures = [orginele_foto, morph_foto]
    facemorpher.morpher(pictures, plot=True, out_frames='output')

    faces = agender.detect_genders_ages(cv2.imread("/Users/ellen/Documents/Twente/Q2/Introduction to biometrics/Final/output/frame009.png"))
    Morphing_age = faces[0]['age']
    return Morphing_age, original_age
示例#2
0
        def one_male(mf):
            for ff in females:
                out_dir = '_'.join((mf.split('.')[0], ff.split('.')[0]))
                pair = [os.path.join('male', mf), os.path.join('female', ff)]
                out_frames = os.path.join(tmp_folder, out_dir)
                print out_frames

                facemorpher.morpher(pair,
                                    percent_list=percent_list,
                                    out_frames=out_frames,
                                    width=226,
                                    height=226)
示例#3
0
def Save_morph_img(orginele_foto, morph_foto, age):
    pictures = [orginele_foto, morph_foto]
    facemorpher.morpher(pictures, plot=True, out_frames='output')

    # Open original image
    img = Image.open("/Users/ellen/Documents/Twente/Q2/Introduction to biometrics/Final/output/frame009.png")
    data = img.load()

    # Makes a copy of the input image and loads the copied image's pixel map
    copyImage = img.copy()

    copyImage.save("/Users/ellen/Documents/Twente/Q2/Introduction to biometrics/Final/test/"+age + '.png')
    copyImage.close()
示例#4
0
for m in models:
    for em in emotions:
        s = 'f' if m < 20 else 'm'
        mstr = '%02d%s' % (m, s)
        outvid = None
        outfr = os.path.join(outdir, mstr + '_' + em + '_' + mouth)
        imgpaths = [
            os.path.join(imdir, 'stim', mstr + '_ne_' + mouth + '.png'),
            os.path.join(imdir, 'stim', mstr + '_' + em + '_' + mouth + '.png')
        ]
        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
def morphing(orginele_foto, morph_foto):
    #agender = PyAgender()
    #faces = agender.detect_genders_ages(cv2.imread(orginele_foto))
    #original_age = faces[0]['age']
    pictures = [orginele_foto, morph_foto]
    facemorpher.morpher(pictures, plot=True, out_frames='output', num_frames=5) # Change 5 -> 20
示例#6
0
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)
示例#7
0
    for m in models:
        for em in emos:
            outfr = os.path.join(outdir, ''.join(v) + m + '_' + em)
            if os.path.exists(outfr) and len(glob(os.path.join(outfr,
                                                               '*'))) >= 50:
                print('%s is already done...' % outfr)
            else:
                imgpaths = [
                    os.path.join(imdir, v[0] + m, v[0] + m + ne + suffix),
                    os.path.join(imdir, v[1] + m, v[1] + m + em + suffix)
                ]
                if os.path.exists(imgpaths[0]) and os.path.exists(imgpaths[1]):
                    fm.morpher(imgpaths,
                               alpha=True,
                               width=w,
                               height=h,
                               num_frames=nframes,
                               fps=10,
                               out_frames=outfr,
                               out_video=None)
                else:
                    print('missing %s/%s' % (imgpaths[0], imgpaths[1]))

noutdir = os.path.join(basedir, 'KDEF', 'out_norm')
if not os.path.exists(noutdir):
    os.makedirs(noutdir)


def feather(img):
    inner_kernel = np.ones((15, 15), np.uint8)
    outer_kernel = np.ones((5, 5), np.uint8)
    a_sm = cv2.erode(img[..., 3], inner_kernel)
def morphing(orginele_foto, morph_foto):
    pictures = [orginele_foto, morph_foto]
    facemorpher.morpher(pictures, plot=True, out_frames='output')
示例#9
0
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)