-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.py
More file actions
37 lines (27 loc) · 880 Bytes
/
get.py
File metadata and controls
37 lines (27 loc) · 880 Bytes
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
import base64
import io
import os
from PIL import Image
from flask import Flask, jsonify, request
from forest_mask import ForestMask
app = Flask(__name__)
@app.route('/api/get', methods=['GET'])
def get():
image_base64 = request.data
image_raw = base64.b64decode(image_base64)
image = Image.open(io.BytesIO(image_raw))
return_image, return_area = ForestMask.get_all(image)
return_image = image_to_base64(return_image)
response = {
'image': return_image,
'area': return_area
}
# we return json with the image and area in m2
return jsonify(response)
def image_to_base64(image):
buffered = io.BytesIO()
image.save(buffered, format='PNG')
img_str = base64.b64encode(buffered.getvalue()).decode('ascii')
return img_str
if __name__ == '__main__':
app.run(debug=True, port=os.getenv("PORT", default=5000))