forked from krishna050702/fdip-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
49 lines (35 loc) · 1.16 KB
/
server.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
import cv2
import numpy as np
import base64
from io import BytesIO
from PIL import Image
from flask import Flask, render_template, request, jsonify
# custom filter
from filters import filterMap
# Route for handling the login page logic
app = Flask(__name__, template_folder="public", static_folder='public/styles')
app.config['UPLOAD_FOLDER'] = "images"
@app.route('/')
def home():
return render_template('index.html')
def readb64(base64_string):
imgdata = base64.b64decode(base64_string)
pimg = Image.open(BytesIO(imgdata))
return cv2.cvtColor(np.array(pimg), cv2.COLOR_RGB2BGR)
@app.route('/filter', methods=['POST'])
def upload_file():
reqData = request.json
# print(len(reqData["imageFile"]))
# converting image in base64 to image
img = readb64(reqData["imageFile"])
if(reqData["filter"] not in filterMap.keys()):
return jsonify({"msg": "filter doesn't exist"})
img2 = filterMap[reqData["filter"]](img)
# print(img2)
data = {
"msg": "filter applied",
"img": str(base64.b64encode(cv2.imencode('.jpg', img2)[1]))
}
return jsonify(data)
if __name__ == '__main__':
app.run(debug=True)