Esempio n. 1
0
from Photo import Photo
from Album import Album

BLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__),
                                './static/johnny_blink6.jpg')
NOBLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__),
                                  './static/johnny_noblink1.jpg')
# BLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/jeff_test/Jeff_blink.PNG')
# NOBLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/jeff_test/jeff_noblink.PNG')

my_album = Album()

blink_photo = Photo(BLINK_PHOTO_PATH)
noblink_photo = Photo(NOBLINK_PHOTO_PATH)

my_album.insert_photo(blink_photo)
my_album.insert_photo(noblink_photo)

my_album.facial_classification()
# blink_photo.blink_detect()
# noblink_photo.blink_detect()

my_album.update_base_photo_index(0)
my_album.blink_detection()
# person_id and photo_id of new face
# my_album.face_swap(swap_person_id = 0, newFace_photo_id = 1)

# search for non blinking face
# non_blinking_face = None

print(blink_photo.id_to_face)
def upload_file():
    # check for numFiles entry
    if 'numFiles' not in request.form or request.form['numFiles'] == "":
        content = {"Error": "Missing 'numFiles' in POST request"}
        return content, 400

    numFiles = int(request.form['numFiles'])

    if numFiles == 0:
        content = {"Error": "No files added in POST request"}
        return content, 400

    if 'basePhotoIndex' not in request.form or request.form[
            'basePhotoIndex'] == "":
        content = {"Error": "Missing 'basePhotoIndex' in POST request"}
        return content, 400

    basePhotoIndex = int(request.form['basePhotoIndex'])

    # Error check
    for i in range(numFiles):
        entry = 'file[' + str(i) + ']'
        if entry not in request.files:
            content = {"Error": "Missing " + entry + " in POST request"}
            return content, 400

        file = request.files[entry]
        if file.filename == '':
            content = {"Error": "File field is empty in POST request"}
            return content, 400

        if not (file and allowed_file(file.filename)):
            content = {
                "Error": "File is wrong format (only accepts png, jpg, jpeg)"
            }
            return content, 400

    # Create a new session
    scale_percent = 0
    newAlbum = Album(scale_percent)
    new_session_id = appSessions.new_session(newAlbum)
    session_path = os.path.join(uploadFolder, new_session_id)
    os.mkdir(session_path)

    output_photo_path = ""
    # Save file in path
    for i in range(numFiles):
        entry = 'file[' + str(i) + ']'
        file = request.files[entry]
        filename = secure_filename(file.filename)

        if (i == basePhotoIndex):
            output_photo_path = os.path.join(session_path,
                                             "retouched_" + filename)
        file.save(os.path.join(session_path, filename))
        newAlbum.insert_photo(Photo(os.path.join(session_path, filename)))

    newAlbum.facial_classification()

    newAlbum.update_base_photo_index(basePhotoIndex)
    newAlbum.blink_detection()

    newAlbum.remove_blinking_faces()
    newAlbum.write_output_photo(output_photo_path)
    newAlbum.status = "READY"
    content = {"session_id": new_session_id}
    return content, 200
Esempio n. 3
0
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../src/'))

from Photo import Photo
from Album import Album

GROUP_PHOTO_1_PATH = os.path.join(os.path.dirname(__file__), './static/group1.jpg')
GROUP_PHOTO_2_PATH = os.path.join(os.path.dirname(__file__), './static/group2.jpg')
GROUP_PHOTO_3_PATH = os.path.join(os.path.dirname(__file__), './static/group3.jpg')

my_album = Album()

group1_photo = Photo(GROUP_PHOTO_1_PATH)
group2_photo = Photo(GROUP_PHOTO_2_PATH)
group3_photo = Photo(GROUP_PHOTO_3_PATH)

my_album.insert_photo(group1_photo)
my_album.insert_photo(group2_photo)
my_album.insert_photo(group3_photo)

my_album.facial_classification()

print(group1_photo.id_to_face)
print(group2_photo.id_to_face)
print(group3_photo.id_to_face)

assert(group1_photo.id_to_face.keys()==group2_photo.id_to_face.keys()==group3_photo.id_to_face.keys())

#todo: test facial classification where different people change