forked from BruceMacD/Face-Swap-OpenCV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
52 lines (41 loc) · 1.18 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File : app.py.py
@Contact : [email protected]
@License : (C)Copyright 2020-2020,
@Modify Time @Author @Version @Desciption
------------ ------- -------- -----------
2020/6/28 5:41 下午 beants 1.0 None
'''
import os
import cv2
from flask import Flask, request, render_template, send_file
#
from components.service import do_swap
#
app = Flask(__name__)
boy_img = cv2.imread("images/boy.jpg")
girl_img = cv2.imread("images/girl.jpg")
@app.route('/')
def hello_world():
return render_template("index.html")
# return 'a'
@app.route('/swap', methods=['POST'])
def swap():
for i in os.listdir('res'):
if os.path.exists('res/' + i):
os.remove('res/' + i)
img = request.files['img']
img.save('temp.jpg')
img = cv2.imread('temp.jpg')
# is_boy = request.form['is_boy']
is_boy = True
if is_boy:
# img_1_face_to_img_2
file_name = do_swap(img, boy_img)
else:
file_name = do_swap(img, girl_img)
return send_file(file_name, mimetype="image/jpg")
if __name__ == '__main__':
app.run(port='2345', host='0.0.0.0')