-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathinterface.py
More file actions
91 lines (73 loc) · 2.28 KB
/
Copy pathinterface.py
File metadata and controls
91 lines (73 loc) · 2.28 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from flask import Flask, request, Response, send_file
import jsonpickle
import numpy as np
import cv2
import io
from makeup import change_color
from test import evaluate
from PIL import Image
import matplotlib.pyplot as plt
app = Flask(__name__)
# localhost:5000/demo?u_lip=0,0,255&l_lip=0,0,255&hair=0,0,255&skin=255,255,255
@app.route("/demo", methods=["GET"])
def apply_makeup():
r = request
np_array = np.frombuffer(r.data, np.uint8)
img = cv2.imdecode(np_array, cv2.IMREAD_COLOR)
cp = "cp/79999_iter.pth"
parsing = evaluate(img, cp)
parsing = cv2.resize(parsing, img.shape[0:2], interpolation=cv2.INTER_NEAREST)
# print([key for key, value in **request.args.get().items()])
modified_img = change_color(img, parsing, **request.args)
cv2.imwrite("img.jpg", cv2.cvtColor(modified_img, cv2.COLOR_BGR2RGB))
response = {
"message": "image received. size={}x{}".format(img.shape[1], img.shape[0])
}
# encode response using jsonpickle
response_pickled = jsonpickle.encode(response)
# pil_image = Image.fromarray(modified_img)
# pil_image = io.StringIO(Image.fromarray(modified_img))
return send_file(
"img.jpg",
mimetype="image/jpeg",
attachment_filename="new.jpeg",
as_attachment=False,
)
if __name__ == "__main__":
app.debug = True
app.run()
#
# from flask import Flask, request, Response, send_file
# import jsonpickle
# import numpy as np
# import cv2
#
# import ImageProcessingFlask
#
# # Initialize the Flask application
# app = Flask(__name__)
#
#
# # route http posts to this method
# @app.route('/api/test', methods=['POST'])
# def test():
# r = request
# # convert string of image data to uint8
# nparr = np.fromstring(r.data, np.uint8)
# # decode image
# img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
#
# # do some fancy processing here....
#
# img = ImageProcessingFlask.render(img)
#
#
# #_, img_encoded = cv2.imencode('.jpg', img)
# #print ( img_encoded)
#
# cv2.imwrite( 'new.jpeg', img)
#
#
# #response_pickled = jsonpickle.encode(response)
# #return Response(response=response_pickled, status=200, mimetype="application/json")
# return send_file( 'new.jpeg', mimetype="image/jpeg", attachment_filename="new.jpeg", as_attachment=True)