-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
103 lines (69 loc) · 2.53 KB
/
Copy pathapp.py
File metadata and controls
103 lines (69 loc) · 2.53 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
92
93
94
95
96
97
98
99
100
101
102
103
from flask import Flask, jsonify, send_file, request
from os import environ
from image_processing.decode import *
import io, base64
from PIL import Image
from image_processing.format import *
import cv2
import requests
app = Flask(__name__)
#global que guarda a imagem
stringIm = ""
@app.route('/receive', methods=['GET','POST'])
def receive_image():
#Retorna erro caso o parametro "foto" não seja recebido ou seja recebido vazio
if not 'foto' in request.files or not request.files.get('foto'):
return jsonify({'erro':'nenhum arquivo'}),400
#define que utilizaremos essa global
global stringIm
#recebe o arquivo
file = request.files.get('foto')
#Imagem salva em variável estática "img"
img = io.BytesIO()
file.save(img)
img.seek(0)
#grava a imagem na nossa variavel global em b64
stringIm = base64.b64encode(img.read())
return "Sucesso"
@app.route('/espreceive', methods=['GET','POST'])
def receive_esp():
#define que utilizaremos essa global
global stringIm
if environ.get("espurl"):
URL = environ.get("espurl")
else:
URL = "https://www.skikelly.com/sf/liveview/?rand=123456789"
#recebe a imagem
response = requests.get(URL)
img = Image.open(io.BytesIO(response.content))
#Converte para PNG
img.save('/tmp/temp.png')
pilImage = Image.open('/tmp/temp.png')
#grava a imagem na nossa variavel global em b64
buffered = io.BytesIO()
pilImage.save(buffered, format="PNG")
stringIm = base64.b64encode(buffered.getvalue())
return "Sucesso"
@app.route('/current_image', methods=['GET'])
def see_image():
global stringIm
#Convertendo nossa string b64 para um arquivo de imagem
imagemF = io.BytesIO(base64.b64decode(stringIm))
imagemF.seek(0)
return send_file(imagemF, mimetype="image/png")
@app.route('/', methods=['GET'])
def get_info():
try:
#conversão da string para imagem e salvamento em diretorio temporario para leitura posterior
imagemF = io.BytesIO(base64.b64decode(stringIm))
pilImage = Image.open(imagemF)
pilImage.save('/tmp/current.png')
image = cv2.imread('/tmp/current.png')
#image = cv2.imread('img/capture (1) - boa.jpg')
a1, a2, p, d, t = decode(image)
apoios, cargas_p, cargas_d, cargas_t = format(a1, a2, p, d, t)
return jsonify(apoios = apoios, cargasP = cargas_p, cargasD = cargas_d, cargasT = cargas_t)
except:
return "Erro ao extrair informações da viga."
if __name__ == '__main__':
app.run(host="0.0.0.0", debug=True)