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
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) print(noblink_photo.id_to_face) # my_album.temp_face_swap(BLINK_PHOTO_PATH,NOBLINK_PHOTO_PATH) my_album.remove_blinking_faces()