def face_swap_api():

    if 'files' not in request.files:
        return Response({'error': 'No files selected'}, status=412)

    files = request.files.getlist('files')

    if len(files) != 2:
        return Response({'error': 'Select Two Faces (Images)'}, status=412)

    face_one = files[0]
    face_two = files[1]

    if allowed_file(face_one.filename) and allowed_file(face_two.filename):
        f1_image = file2image(face_one)
        f2_image = file2image(face_two)

        logger.info(f'Running FaceSwap')
        swapped_face = swap_faces(f1_image, f2_image)

        # convert it to bytes
        b64_image = image2b64(swapped_face)

        return jsonify(b64_image), 200

    else:
        return Response({'error': f'{face_one.mimetype} not allowed'},
                        status=412)
示例#2
0
def fetch_apparel(image, mask):
    apparels = {}
    for ax in range(mask.shape[-1]):
        m = mask[:, :, ax]
        roi = cv2.bitwise_and(image, image, mask=m)
        if m.any():  # add only if class is present
            title = CLASSES[ax]
            roi[roi < 1] = 255  # make background white
            roi = image2b64(roi)  # encode image
            apparels[title] = roi
    return apparels
def face_align_api():
    if 'file' not in request.files:
        return Response({'error': 'No file part'}, status=412)

    file: FileStorage = request.files['file']

    if file.filename == '':
        return Response({'error': 'No file selected'}, status=417)

    if allowed_file(file.filename):
        image = file2image(file)

        logger.info(f'Running Align Face on {file.filename}')

        # align the face
        aligned_face = align_face(image)

        # convert it to bytes
        b64_image = image2b64(aligned_face)

        return jsonify(b64_image), 200

    else:
        return Response({'error': f'{file.mimetype} not allowed'}, status=412)